Skip to content

Commit b71cadb

Browse files
authored
All regeneration of test data when it doesn't already exist (#295)
fail fast conflicts with this at present. Also allow the ability to run a single test with `npm test -- --save-output --single-test testNAME`
1 parent 3b19cbb commit b71cadb

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,27 @@ filesystem output (typically `bundle.js` and possibly `bundle.js.map`) and any
6565
console output. stdout should go in `output.txt` and stderr should go in
6666
`err.txt`.
6767

68+
If you would like to run just a single test then supply the name of it like so:
69+
70+
`npm test -- --single-test declarationOutput`
71+
72+
### Regenerating test data
73+
6874
As a convenience it is possible to regenerate the expected output from the
6975
actual output. This is useful when creating new tests and also when making a
70-
change that affects multiple existing tests. To run use
71-
`npm test -- --save-output`. Note that all tests will automatically pass when
76+
change that affects multiple existing tests. To run use:
77+
78+
`npm test -- --save-output`.
79+
80+
Note that all tests will automatically pass when
7281
using this feature. You should double check the generated files to make sure
7382
the output is indeed correct.
7483

84+
If you would like to regenerate a single test then combine `--save-output` with
85+
`--single-test` like so:
86+
87+
`npm test -- --save-output --single-test declarationOutput`
88+
7589
The test harness additionally supports watch mode since that is such an
7690
integral part of webpack. The initial state is as described above. After the
7791
initial state is compiled, a series of "patches" can be applied and tested. The

test/run.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ var glob = require('glob');
1313
// force colors on for tests since expected output has colors
1414
require('colors').enabled = true;
1515

16-
var saveOutputMode = process.argv.indexOf('--save-output') != -1;
16+
var saveOutputMode = process.argv.indexOf('--save-output') !== -1;
17+
18+
var indexOfSingleTest = process.argv.indexOf('--single-test');
19+
var singleTestToRun = indexOfSingleTest !== -1 && process.argv[indexOfSingleTest + 1];
1720

1821
var savedOutputs = {};
1922

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

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

43+
if (singleTestToRun && singleTestToRun !== test) return;
44+
4045
describe(test, function() {
4146
it('should have the correct output', createTest(test, testPath, {}));
4247

@@ -48,14 +53,14 @@ fs.readdirSync(__dirname).forEach(function(test) {
4853
}
4954
});
5055

51-
function fileExists(path) {
52-
var fileExists = true;
56+
function pathExists(path) {
57+
var pathExists = true;
5358
try {
5459
fs.accessSync(path, fs.F_OK);
5560
} catch (e) {
56-
fileExists = false;
61+
pathExists = false;
5762
}
58-
return fileExists;
63+
return pathExists;
5964
}
6065

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

72-
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)
73-
7477
if (saveOutputMode) {
7578
savedOutputs[test] = savedOutputs[test] || {};
7679
var regularSavedOutput = savedOutputs[test].regular = savedOutputs[test].regular || {};
7780
var transpiledSavedOutput = savedOutputs[test].transpiled = savedOutputs[test].transpiled || {};
7881
var currentSavedOutput = options.transpile ? transpiledSavedOutput : regularSavedOutput;
7982
mkdirp.sync(originalExpectedOutput);
83+
} else {
84+
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)
8085
}
8186

8287
// copy all input to a staging area

0 commit comments

Comments
 (0)