Skip to content

Commit

Permalink
All regeneration of test data when it doesn't already exist (#295)
Browse files Browse the repository at this point in the history
fail fast conflicts with this at present.  Also allow the ability to run
a single test with `npm test -- --save-output --single-test testNAME`
  • Loading branch information
johnnyreilly authored Oct 6, 2016
1 parent 3b19cbb commit b71cadb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
18 changes: 16 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,27 @@ filesystem output (typically `bundle.js` and possibly `bundle.js.map`) and any
console output. stdout should go in `output.txt` and stderr should go in
`err.txt`.

If you would like to run just a single test then supply the name of it like so:

`npm test -- --single-test declarationOutput`

### Regenerating test data

As a convenience it is possible to regenerate the expected output from the
actual output. This is useful when creating new tests and also when making a
change that affects multiple existing tests. To run use
`npm test -- --save-output`. Note that all tests will automatically pass when
change that affects multiple existing tests. To run use:

`npm test -- --save-output`.

Note that all tests will automatically pass when
using this feature. You should double check the generated files to make sure
the output is indeed correct.

If you would like to regenerate a single test then combine `--save-output` with
`--single-test` like so:

`npm test -- --save-output --single-test declarationOutput`

The test harness additionally supports watch mode since that is such an
integral part of webpack. The initial state is as described above. After the
initial state is compiled, a series of "patches" can be applied and tested. The
Expand Down
19 changes: 12 additions & 7 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ var glob = require('glob');
// force colors on for tests since expected output has colors
require('colors').enabled = true;

var saveOutputMode = process.argv.indexOf('--save-output') != -1;
var saveOutputMode = process.argv.indexOf('--save-output') !== -1;

var indexOfSingleTest = process.argv.indexOf('--single-test');
var singleTestToRun = indexOfSingleTest !== -1 && process.argv[indexOfSingleTest + 1];

var savedOutputs = {};

Expand All @@ -37,6 +40,8 @@ fs.readdirSync(__dirname).forEach(function(test) {

if (test == 'issue81' && semver.lt(typescript.version, '1.7.0-0')) return;

if (singleTestToRun && singleTestToRun !== test) return;

describe(test, function() {
it('should have the correct output', createTest(test, testPath, {}));

Expand All @@ -48,14 +53,14 @@ fs.readdirSync(__dirname).forEach(function(test) {
}
});

function fileExists(path) {
var fileExists = true;
function pathExists(path) {
var pathExists = true;
try {
fs.accessSync(path, fs.F_OK);
} catch (e) {
fileExists = false;
pathExists = false;
}
return fileExists;
return pathExists;
}

function createTest(test, testPath, options) {
Expand All @@ -69,14 +74,14 @@ function createTest(test, testPath, options) {
webpackOutput = path.join(testStagingPath, '.output'),
originalExpectedOutput = path.join(testPath, 'expectedOutput-'+typescriptVersion);

assert.ok(fileExists(originalExpectedOutput), 'The expected output does not exist; there is nothing to compare against! Has the expected output been created?\nCould not find: ' + originalExpectedOutput)

if (saveOutputMode) {
savedOutputs[test] = savedOutputs[test] || {};
var regularSavedOutput = savedOutputs[test].regular = savedOutputs[test].regular || {};
var transpiledSavedOutput = savedOutputs[test].transpiled = savedOutputs[test].transpiled || {};
var currentSavedOutput = options.transpile ? transpiledSavedOutput : regularSavedOutput;
mkdirp.sync(originalExpectedOutput);
} else {
assert.ok(pathExists(originalExpectedOutput), 'The expected output does not exist; there is nothing to compare against! Has the expected output been created?\nCould not find: ' + originalExpectedOutput)
}

// copy all input to a staging area
Expand Down

0 comments on commit b71cadb

Please sign in to comment.