stajs / dnxflow Goto Github PK
View Code? Open in Web Editor NEWSee https://github.com/stajs/SpecFlow.NetCore instead
See https://github.com/stajs/SpecFlow.NetCore instead
After following these steps for setting up SpecFlow.NetCore
I got this working with our netcore and nUnit project. I figured out that there are somethings in the gulpfile.js that need to be set:
var fakeCsprojFilename = 'Fake_SpecFlow_Fix.csproj';
var xprojFilename = 'MY_REAL_PROJECT_NAME.xproj'; // change this to your .xproj file
Then I added this to packages.json for greater debug output
"devDependencies": {
...
"gulp-util": "3.0.8"
},
I renamed the gulp task to 'Build_SpecFlow_CodeBehindFiles' and binded it to a Task Runner Before Build step in Visual Studio. Works beautifully. Thanks!!
Now the complete gulpfile.js is:
/// <binding BeforeBuild='Build_SpecFlow_CodeBehindFiles' />
var gulp = require('gulp'),
execSync = require('child_process').execSync,
tap = require('gulp-tap'),
path = require('path'),
fs = require('fs'),
glob = require('glob'),
replace = require('gulp-replace'),
gulpUtil = require('gulp-util');
var specflowToolsPath = '..\\packages\\SpecFlow.2.2.0\\tools\\specflow.exe';
var fakeCsprojContent = '';
var fakeCsprojFilename = 'Fake_SpecFlow_Fix.csproj';
var xprojFilename = 'MY_REAL_PROJECT_NAME.xproj';
function gulpLog(msg) {
gulpUtil.log(msg);
}
gulp.task('getFilenames', function (cb) {
try {
xprojFilename = glob.sync('*.xproj')[0];
} catch (e) {
gulpLog('Couldn\'t glob for xproj!');
throw e;
}
gulpLog('Found xproj: ' + xprojFilename);
fakeCsprojFilename = xprojFilename.replace('.xproj', '.csproj.fake');
gulpLog('Fake csproj: ' + fakeCsprojFilename);
cb();
});
gulp.task('generateFakeCsproj', ['getFilenames'], function (cb) {
fakeCsprojContent = '<?xml version="1.0" encoding="utf-8"?>' +
// Set the "ToolsVersion" to VS2013, see: https://github.com/techtalk/SpecFlow/issues/471
'\n<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' +
'\n <PropertyGroup>' +
'\n <RootNamespace>' + xprojFilename.replace('.xproj', '') + '</RootNamespace>' +
'\n </PropertyGroup>' +
'\n <ItemGroup>' +
'\n <None Include="app.config">' +
'\n <SubType>Designer</SubType>' +
'\n </None>';
gulp.src('**/**.feature')
.pipe(tap(function (file) {
var relativePath = file.path.replace(file.cwd + '\\', '');
fakeCsprojContent +=
'\n <None Include="' + relativePath + '">' +
'\n <Generator>SpecFlowSingleFileGenerator</Generator>' +
'\n <LastGenOutput>' + path.basename(file.path) + '.cs</LastGenOutput>' +
'\n </None>';
}))
.on('end', function () {
fakeCsprojContent +=
'\n </ItemGroup>' +
'\n</Project>';
gulpLog(fakeCsprojContent);
try {
fs.writeFileSync(fakeCsprojFilename, fakeCsprojContent);
} catch (e) {
gulpLog('Couldn\'t save fake csproj!');
throw e;
}
gulpLog('File saved!');
cb();
});
});
gulp.task('generateSpecFlowGlue', ['generateFakeCsproj'], function (cb) {
var specflowExe = path.join(specflowToolsPath);
try {
fs.accessSync(specflowExe, fs.F_OK | fs.X_OK);
} catch (e) {
gulpLog('Couldn\'t find specflow.exe!');
throw e;
}
// Credit: http://stackoverflow.com/questions/11363202/specflow-fails-when-trying-to-generate-test-execution-report
var configFile = specflowExe + '.config';
var configFileContents = '<?xml version="1.0" encoding="utf-8" ?><configuration><startup><supportedRuntime version="v4.0.30319" /></startup></configuration>';
try {
fs.writeFileSync(configFile, configFileContents);
} catch (e) {
gulpLog('Couldn\'t write specflow config file!');
throw e;
}
gulpLog('Created: ' + configFile);
// Credit: http://www.marcusoft.net/2010/12/specflowexe-and-mstest.html
var command = specflowExe + ' generateall ' + fakeCsprojFilename + ' /force /verbose';
gulpLog('Calling: ' + command);
execSync(command, { stdio: [0, 1, 2] });
try {
fs.unlinkSync(configFile);
} catch (e) {
gulpLog('Couldn\'t remove (clean up) specflow config file!');
throw e;
}
gulpLog('Removed: ' + configFile);
cb();
});
gulp.task('xUnitTwoFix', ['generateSpecFlowGlue'], function () {
gulpLog('Fixing SpecFlow generated files for xUnit v2');
return gulp.src('**/**.feature.cs')
.pipe(replace(' : Xunit.IUseFixture<', ' : Xunit.IClassFixture<'))
.pipe(gulp.dest(function (file) {
gulpLog("Fixed: " + file.path);
return file.base;
}));
});
gulp.task('Build_SpecFlow_CodeBehindFiles', ['xUnitTwoFix']);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.