Code Monkey home page Code Monkey logo

dnxflow's People

Contributors

stajs avatar

Watchers

 avatar  avatar

dnxflow's Issues

Getting this working with netcore and nUnit

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']);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.