Skip to content

Commit 9d62b44

Browse files
committed
Fix comparison tests where the multiple compilation callbacks were not handled so it didnt show correct output
1 parent e3bd56e commit 9d62b44

File tree

15 files changed

+122
-159
lines changed

15 files changed

+122
-159
lines changed

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

+42-17
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,38 @@ function createWebpackConfig(paths, optionsOriginal, useWatchApi) {
177177
}
178178

179179
function createWebpackWatchHandler(done, paths, testState, options, test) {
180+
let timoutId;
181+
let statsString;
182+
let errString;
180183
return function (err, stats) {
184+
if (timoutId) {
185+
clearTimeout(timoutId);
186+
timoutId = undefined;
187+
}
181188
const patch = setPathsAndGetPatch(paths, testState, options);
189+
const currentErrString = errToString(err, paths);
190+
if (currentErrString) {
191+
errString = errString ? errString + "\n\n" + currentErrString : currentErrString;
192+
}
193+
const currentStatsString = statsToString(stats, testState, paths);
194+
if (currentStatsString) {
195+
statsString = statsString ? statsString + "\n\n" + currentStatsString : currentStatsString;
196+
}
197+
timoutId = setTimeout(function () {
198+
cleanHashFromOutput(stats, paths.webpackOutput);
182199

183-
cleanHashFromOutput(stats, paths.webpackOutput);
184-
185-
copySync(paths.webpackOutput, paths.actualOutput);
186-
rimraf.sync(paths.webpackOutput);
187-
188-
handleErrors(err, paths);
200+
copySync(paths.webpackOutput, paths.actualOutput);
201+
rimraf.sync(paths.webpackOutput);
189202

190-
storeStats(stats, testState, paths);
203+
handleErrors(errString, paths);
204+
errString = undefined;
191205

192-
compareFiles(paths, test, patch);
206+
storeStats(statsString, paths);
207+
statsString = undefined;
193208

194-
copyPatchOrEndTest(paths.testStagingPath, testState.watcher, testState, done);
209+
compareFiles(paths, test, patch);
210+
copyPatchOrEndTest(paths.testStagingPath, testState.watcher, testState, done);
211+
}, 2000);
195212
}
196213
}
197214

@@ -210,26 +227,35 @@ function setPathsAndGetPatch(paths, testState, options) {
210227
return patch;
211228
}
212229

213-
function handleErrors(err, paths) {
214-
if (err) {
230+
function handleErrors(errString, paths) {
231+
if (errString) {
215232
const errFileName = 'err.txt';
233+
fs.writeFileSync(path.join(paths.actualOutput, errFileName), errString);
234+
}
235+
}
216236

237+
function errToString(err, paths) {
238+
if (err) {
217239
const errString = err.toString()
218240
.replace(new RegExp(regexEscape(paths.testStagingPath + path.sep), 'g'), '')
219241
.replace(new RegExp(regexEscape(rootPath + path.sep), 'g'), '')
220242
.replace(new RegExp(regexEscape(rootPath), 'g'), '')
221243
.replace(/\.transpile/g, '');
244+
return errString;
245+
}
246+
}
222247

223-
fs.writeFileSync(path.join(paths.actualOutput, errFileName), errString);
248+
function storeStats(statsString, paths) {
249+
if (statsString) {
250+
const statsFileName = 'output.txt';
251+
fs.writeFileSync(path.join(paths.actualOutput, statsFileName), statsString);
224252
}
225253
}
226254

227-
function storeStats(stats, testState, paths) {
255+
function statsToString(stats, testState, paths) {
228256
if (stats && stats.hash !== testState.lastHash) {
229257
testState.lastHash = stats.hash;
230258

231-
const statsFileName = 'output.txt';
232-
233259
// do a little magic to normalize `\` to `/` for asset output
234260
const newAssets = {};
235261
Object.keys(stats.compilation.assets).forEach(function (asset) {
@@ -244,8 +270,7 @@ function storeStats(stats, testState, paths) {
244270
.replace(new RegExp(regexEscape(rootPath), 'g'), '')
245271
.replace(new RegExp(regexEscape(rootPathWithIncorrectWindowsSeparator), 'g'), '')
246272
.replace(/\.transpile/g, '');
247-
248-
fs.writeFileSync(path.join(paths.actualOutput, statsFileName), statsString);
273+
return statsString;
249274
}
250275
}
251276

test/comparison-tests/projectReferencesMultiple/expectedOutput-transpile-3.8/output.txt

+37
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,43 @@ ERROR in [tsl] ERROR in [36
2020
ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
2121
 TS2322: Type 'false' is not assignable to type 'string'.
2222

23+
ERROR in ./lib/index.ts
24+
Module build failed (from /index.js):
25+
Error: TypeScript emitted no output for lib\index.ts. The most common cause for this is having errors when building referenced projects.
26+
at makeSourceMapAndFinish (dist\index.js:87:18)
27+
at successLoader (dist\index.js:73:9)
28+
at Object.loader (dist\index.js:24:5)
29+
@ ./app.ts 3:12-28
30+
31+
ERROR in ./utils/index.ts
32+
Module build failed (from /index.js):
33+
Error: TypeScript emitted no output for utils\index.ts. The most common cause for this is having errors when building referenced projects.
34+
at makeSourceMapAndFinish (dist\index.js:87:18)
35+
at successLoader (dist\index.js:73:9)
36+
at Object.loader (dist\index.js:24:5)
37+
@ ./app.ts 4:14-32
38+
39+
Asset Size Chunks Chunk Names
40+
bundle.js 5.57 KiB main main
41+
Entrypoint main = bundle.js
42+
[./app.ts] 218 bytes {main} [2 errors]
43+
[./lib/index.ts] 493 bytes {main} [built] [failed] [3 errors]
44+
[./utils/index.ts] 495 bytes {main} [built] [failed] [1 error]
45+
46+
ERROR in [tsl] ERROR in indirectWithError\fileWithError.ts(2,5)
47+
 TS2322: Type 'false' is not assignable to type 'string'.
48+
49+
ERROR in [tsl] ERROR in indirectWithError\fileWithError.ts(2,5)
50+
 TS2322: Type 'false' is not assignable to type 'string'.
51+
@ ./app.ts 3:12-28
52+
53+
ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
54+
 TS2322: Type 'false' is not assignable to type 'string'.
55+
56+
ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
57+
 TS2322: Type 'false' is not assignable to type 'string'.
58+
@ ./app.ts 3:12-28
59+
2360
ERROR in ./lib/index.ts
2461
Module build failed (from /index.js):
2562
Error: TypeScript emitted no output for lib\index.ts. The most common cause for this is having errors when building referenced projects.

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-3.8/patch0/bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */
106106
/***/ (function(module, exports, __webpack_require__) {
107107

108108
"use strict";
109-
eval("\nexports.__esModule = true;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack:///./lib/out/index.js?");
109+
eval("\nexports.__esModule = true;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3,\n four: 4 // Add new number\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack:///./lib/out/index.js?");
110110

111111
/***/ })
112112

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-3.8/patch0/output.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
../lib/out/tsconfig.tsbuildinfo 70 KiB [emitted]
77
Entrypoint main = bundle.js
88
[./app.ts] 131 bytes {main} [built]
9-
[./lib/out/index.js] 130 bytes {main}
9+
[./lib/out/index.js] 130 bytes {main}
10+
11+
Asset Size Chunks Chunk Names
12+
bundle.js 4.37 KiB main [emitted] main
13+
Entrypoint main = bundle.js
14+
[./app.ts] 131 bytes {main}
15+
[./lib/out/index.js] 161 bytes {main} [built]

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-3.8/patch1/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
bundle.js 4.4 KiB main [emitted] main
33
Entrypoint main = bundle.js
44
[./app.ts] 169 bytes {main} [built]
5-
[./lib/out/index.js] 161 bytes {main} [built]
5+
[./lib/out/index.js] 161 bytes {main}

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-3.8/patch3/bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */
106106
/***/ (function(module, exports, __webpack_require__) {
107107

108108
"use strict";
109-
eval("\nexports.__esModule = true;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3,\n four: 4 // Add new number\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack:///./lib/out/index.js?");
109+
eval("\nexports.__esModule = true;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3,\n four: 4,\n five: 5\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack:///./lib/out/index.js?");
110110

111111
/***/ })
112112

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-3.8/patch3/output.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
../lib/out/tsconfig.tsbuildinfo 70 KiB [emitted]
77
Entrypoint main = bundle.js
88
[./app.ts] 169 bytes {main} [built]
9-
[./lib/out/index.js] 161 bytes {main}
9+
[./lib/out/index.js] 161 bytes {main}
10+
11+
Asset Size Chunks Chunk Names
12+
bundle.js 4.4 KiB main [emitted] main
13+
Entrypoint main = bundle.js
14+
[./app.ts] 169 bytes {main}
15+
[./lib/out/index.js] 156 bytes {main} [built]

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-3.8/patch4/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
bundle.js 4.42 KiB main [emitted] main
33
Entrypoint main = bundle.js
44
[./app.ts] 186 bytes {main} [built] [1 error]
5-
[./lib/out/index.js] 156 bytes {main} [built]
5+
[./lib/out/index.js] 156 bytes {main}
66

77
ERROR in app.ts
88
./app.ts

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-transpile-3.8/patch0/bundle.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@
9494
/***/ (function(module, exports, __webpack_require__) {
9595

9696
"use strict";
97-
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three);\n\n\n//# sourceURL=webpack:///./app.ts?");
97+
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/out/index.js\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three);\n\n\n//# sourceURL=webpack:///./app.ts?");
9898

9999
/***/ }),
100100

101-
/***/ "./lib/index.ts":
102-
/*!**********************!*\
103-
!*** ./lib/index.ts ***!
104-
\**********************/
101+
/***/ "./lib/out/index.js":
102+
/*!**************************!*\
103+
!*** ./lib/out/index.js ***!
104+
\**************************/
105105
/*! no static exports found */
106106
/***/ (function(module, exports, __webpack_require__) {
107107

108108
"use strict";
109-
eval("\r\nexports.__esModule = true;\r\nexports.lib = {\r\n one: 1,\r\n two: 2,\r\n three: 3,\r\n four: 4 // Add new number\r\n};\r\n\n\n//# sourceURL=webpack:///./lib/index.ts?");
109+
eval("\nexports.__esModule = true;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3,\n four: 4 // Add new number\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack:///./lib/out/index.js?");
110110

111111
/***/ })
112112

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
Asset Size Chunks Chunk Names
2-
bundle.js 4.36 KiB main [emitted] main
3-
../lib/out/index.js 169 bytes [emitted]
4-
../lib/out/tsconfig.tsbuildinfo 70 KiB [emitted]
5-
../lib/out/index.js.map 223 bytes [emitted]
6-
../lib/out/index.d.ts 108 bytes [emitted]
1+
Asset Size Chunks Chunk Names
2+
bundle.js 4.4 KiB main [emitted] main
73
Entrypoint main = bundle.js
8-
[./app.ts] 167 bytes {main} [built]
9-
[./lib/index.ts] 136 bytes {main} [built]
4+
[./app.ts] 167 bytes {main}
5+
[./lib/out/index.js] 161 bytes {main} [built]

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-transpile-3.8/patch1/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
bundle.js 4.44 KiB main [emitted] main
33
Entrypoint main = bundle.js
44
[./app.ts] 205 bytes {main} [built]
5-
[./lib/out/index.js] 161 bytes {main} [built]
5+
[./lib/out/index.js] 161 bytes {main}

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-transpile-3.8/patch2/bundle.js

-113
This file was deleted.

test/comparison-tests/projectReferencesOutDirWithPackageJsonAlreadyBuilt/expectedOutput-transpile-3.8/patch3/bundle.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@
9494
/***/ (function(module, exports, __webpack_require__) {
9595

9696
"use strict";
97-
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three, lib_1.lib.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");
97+
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/out/index.js\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three, lib_1.lib.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");
9898

9999
/***/ }),
100100

101-
/***/ "./lib/index.ts":
102-
/*!**********************!*\
103-
!*** ./lib/index.ts ***!
104-
\**********************/
101+
/***/ "./lib/out/index.js":
102+
/*!**************************!*\
103+
!*** ./lib/out/index.js ***!
104+
\**************************/
105105
/*! no static exports found */
106106
/***/ (function(module, exports, __webpack_require__) {
107107

108108
"use strict";
109-
eval("\r\nexports.__esModule = true;\r\nexports.lib = {\r\n one: 1,\r\n two: 2,\r\n three: 3,\r\n four: 4,\r\n five: 5\r\n};\r\n\n\n//# sourceURL=webpack:///./lib/index.ts?");
109+
eval("\nexports.__esModule = true;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3,\n four: 4,\n five: 5\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack:///./lib/out/index.js?");
110110

111111
/***/ })
112112

0 commit comments

Comments
 (0)