Skip to content

Commit 16f6f39

Browse files
committed
start making comparison test pack more configurable
1 parent 4671658 commit 16f6f39

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

test/comparison-tests/create-and-execute-test.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,20 @@ if (fs.statSync(testPath).isDirectory() &&
5858
testToRun === 'appendSuffixToWatch') { return; }
5959

6060
// @ts-ignore
61-
it('should work with transpile', createTest(testToRun, testPath, { transpile: true }));
61+
it('should work with transpileOnly', createTest(testToRun, testPath, { transpileOnly: true }));
62+
63+
// The future....
64+
// it('should work with experimentalFileCaching', createTest(testToRun, testPath, { experimentalFileCaching: true }));
6265
});
6366
}
6467

68+
69+
/**
70+
* Create a Jasmine test
71+
* @param {string} test
72+
* @param {string} testPath
73+
* @param {any} options
74+
*/
6575
function createTest(test, testPath, options) {
6676
return function (done) {
6777
this.timeout(60000); // sometimes it just takes awhile
@@ -82,7 +92,7 @@ function createTest(test, testPath, options) {
8292

8393
// execute webpack
8494
testState.watcher = webpack(
85-
createWebpackConfig(paths, options.transpile)
95+
createWebpackConfig(paths, options)
8696
).watch({ aggregateTimeout: 1500 }, createWebpackWatchHandler(done, paths, testState, outputs, options, test));
8797
};
8898
}
@@ -97,7 +107,7 @@ function createTestState() {
97107
}
98108

99109
function createPaths(stagingPath, test, options) {
100-
var testStagingPath = path.join(stagingPath, test + (options.transpile ? '.transpile' : ''));
110+
var testStagingPath = path.join(stagingPath, test + (options.transpileOnly ? '.transpile' : ''));
101111
return {
102112
testStagingPath: testStagingPath,
103113
actualOutput: path.join(testStagingPath, 'actualOutput'),
@@ -121,26 +131,24 @@ function storeSavedOutputs(saveOutputMode, outputs, test, options, paths) {
121131

122132
outputs.regularSavedOutput = savedOutputs[test].regular = savedOutputs[test].regular || {};
123133
outputs.transpiledSavedOutput = savedOutputs[test].transpiled = savedOutputs[test].transpiled || {};
124-
outputs.currentSavedOutput = options.transpile ? outputs.transpiledSavedOutput : outputs.regularSavedOutput;
134+
outputs.currentSavedOutput = options.transpileOnly ? outputs.transpiledSavedOutput : outputs.regularSavedOutput;
125135

126136
mkdirp.sync(paths.originalExpectedOutput);
127137
} else {
128138
assert.ok(pathExists(paths.originalExpectedOutput), 'The expected output does not exist; there is nothing to compare against! Has the expected output been created?\nCould not find: ' + paths.originalExpectedOutput)
129139
}
130140
}
131141

132-
function createWebpackConfig(paths, transpile) {
142+
function createWebpackConfig(paths, optionsOriginal) {
133143
var config = require(path.join(paths.testStagingPath, 'webpack.config'));
134144

135-
var options = {
145+
var options = Object.assign({
136146
// colors: false,
137147
silent: true,
138148
compilerOptions: {
139149
newLine: 'LF'
140150
}
141-
}
142-
143-
if (transpile) { options.transpileOnly = true; }
151+
}, optionsOriginal);
144152

145153
var tsLoaderPath = require('path').join(__dirname, "../../index.js");
146154

@@ -203,7 +211,7 @@ function saveOutputIfRequired(saveOutputMode, paths, outputs, options, patch) {
203211
var patchedFileName = patch + '/' + file;
204212
outputs.currentSavedOutput[patchedFileName] = fs.readFileSync(path.join(paths.webpackOutput, file), 'utf-8');
205213

206-
if (options.transpile) {
214+
if (options.transpileOnly) {
207215
if (outputs.regularSavedOutput[patchedFileName] !== outputs.transpiledSavedOutput[patchedFileName]) {
208216
var extension = path.extname(file);
209217
fs.renameSync(
@@ -233,7 +241,7 @@ function handleErrors(err, paths, outputs, patch, options) {
233241
var patchedErrFileName = patch + '/' + errFileName;
234242
outputs.currentSavedOutput[patchedErrFileName] = errString;
235243

236-
if (options.transpile) {
244+
if (options.transpileOnly) {
237245
if (outputs.regularSavedOutput[patchedErrFileName] !== outputs.transpiledSavedOutput[patchedErrFileName]) {
238246
fs.writeFileSync(path.join(paths.originalExpectedOutput, 'err.transpiled.txt'), errString);
239247
}
@@ -271,7 +279,7 @@ function storeStats(stats, testState, paths, outputs, patch, options) {
271279
var patchedStatsFileName = patch + '/' + statsFileName;
272280
outputs.currentSavedOutput[patchedStatsFileName] = statsString;
273281

274-
if (options.transpile) {
282+
if (options.transpileOnly) {
275283
if (outputs.regularSavedOutput[patchedStatsFileName] !== outputs.transpiledSavedOutput[patchedStatsFileName]) {
276284
fs.writeFileSync(path.join(paths.originalExpectedOutput, 'output.transpiled.txt'), statsString);
277285
}
@@ -288,7 +296,7 @@ function compareFiles(paths, options, test, patch) {
288296
// massage any .transpiled. files
289297
glob.sync('**/*', { cwd: paths.expectedOutput, nodir: true }).forEach(function (file) {
290298
if (/\.transpiled/.test(file)) {
291-
if (options.transpile) { // rename if we're in transpile mode
299+
if (options.transpileOnly) { // rename if we're in transpile mode
292300
var extension = path.extname(file);
293301
fs.renameSync(
294302
path.join(paths.expectedOutput, file),

0 commit comments

Comments
 (0)