Skip to content

Commit

Permalink
Fix comparison tests where the multiple compilation callbacks were no…
Browse files Browse the repository at this point in the history
…t handled so it didnt show correct output
  • Loading branch information
sheetalkamat committed Apr 10, 2020
1 parent e3bd56e commit 9d62b44
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 159 deletions.
59 changes: 42 additions & 17 deletions test/comparison-tests/create-and-execute-test.js
Expand Up @@ -177,21 +177,38 @@ function createWebpackConfig(paths, optionsOriginal, useWatchApi) {
}

function createWebpackWatchHandler(done, paths, testState, options, test) {
let timoutId;
let statsString;
let errString;
return function (err, stats) {
if (timoutId) {
clearTimeout(timoutId);
timoutId = undefined;
}
const patch = setPathsAndGetPatch(paths, testState, options);
const currentErrString = errToString(err, paths);
if (currentErrString) {
errString = errString ? errString + "\n\n" + currentErrString : currentErrString;
}
const currentStatsString = statsToString(stats, testState, paths);
if (currentStatsString) {
statsString = statsString ? statsString + "\n\n" + currentStatsString : currentStatsString;
}
timoutId = setTimeout(function () {
cleanHashFromOutput(stats, paths.webpackOutput);

cleanHashFromOutput(stats, paths.webpackOutput);

copySync(paths.webpackOutput, paths.actualOutput);
rimraf.sync(paths.webpackOutput);

handleErrors(err, paths);
copySync(paths.webpackOutput, paths.actualOutput);
rimraf.sync(paths.webpackOutput);

storeStats(stats, testState, paths);
handleErrors(errString, paths);
errString = undefined;

compareFiles(paths, test, patch);
storeStats(statsString, paths);
statsString = undefined;

copyPatchOrEndTest(paths.testStagingPath, testState.watcher, testState, done);
compareFiles(paths, test, patch);
copyPatchOrEndTest(paths.testStagingPath, testState.watcher, testState, done);
}, 2000);
}
}

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

function handleErrors(err, paths) {
if (err) {
function handleErrors(errString, paths) {
if (errString) {
const errFileName = 'err.txt';
fs.writeFileSync(path.join(paths.actualOutput, errFileName), errString);
}
}

function errToString(err, paths) {
if (err) {
const errString = err.toString()
.replace(new RegExp(regexEscape(paths.testStagingPath + path.sep), 'g'), '')
.replace(new RegExp(regexEscape(rootPath + path.sep), 'g'), '')
.replace(new RegExp(regexEscape(rootPath), 'g'), '')
.replace(/\.transpile/g, '');
return errString;
}
}

fs.writeFileSync(path.join(paths.actualOutput, errFileName), errString);
function storeStats(statsString, paths) {
if (statsString) {
const statsFileName = 'output.txt';
fs.writeFileSync(path.join(paths.actualOutput, statsFileName), statsString);
}
}

function storeStats(stats, testState, paths) {
function statsToString(stats, testState, paths) {
if (stats && stats.hash !== testState.lastHash) {
testState.lastHash = stats.hash;

const statsFileName = 'output.txt';

// do a little magic to normalize `\` to `/` for asset output
const newAssets = {};
Object.keys(stats.compilation.assets).forEach(function (asset) {
Expand All @@ -244,8 +270,7 @@ function storeStats(stats, testState, paths) {
.replace(new RegExp(regexEscape(rootPath), 'g'), '')
.replace(new RegExp(regexEscape(rootPathWithIncorrectWindowsSeparator), 'g'), '')
.replace(/\.transpile/g, '');

fs.writeFileSync(path.join(paths.actualOutput, statsFileName), statsString);
return statsString;
}
}

Expand Down
Expand Up @@ -20,6 +20,43 @@ ERROR in [tsl] ERROR in [36
ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.

ERROR in ./lib/index.ts
Module build failed (from /index.js):
Error: TypeScript emitted no output for lib\index.ts. The most common cause for this is having errors when building referenced projects.
at makeSourceMapAndFinish (dist\index.js:87:18)
at successLoader (dist\index.js:73:9)
at Object.loader (dist\index.js:24:5)
@ ./app.ts 3:12-28

ERROR in ./utils/index.ts
Module build failed (from /index.js):
Error: TypeScript emitted no output for utils\index.ts. The most common cause for this is having errors when building referenced projects.
at makeSourceMapAndFinish (dist\index.js:87:18)
at successLoader (dist\index.js:73:9)
at Object.loader (dist\index.js:24:5)
@ ./app.ts 4:14-32

Asset Size Chunks Chunk Names
bundle.js 5.57 KiB main main
Entrypoint main = bundle.js
[./app.ts] 218 bytes {main} [2 errors]
[./lib/index.ts] 493 bytes {main} [built] [failed] [3 errors]
[./utils/index.ts] 495 bytes {main} [built] [failed] [1 error]

ERROR in [tsl] ERROR in indirectWithError\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.

ERROR in [tsl] ERROR in indirectWithError\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.
@ ./app.ts 3:12-28

ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.

ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.
@ ./app.ts 3:12-28

ERROR in ./lib/index.ts
Module build failed (from /index.js):
Error: TypeScript emitted no output for lib\index.ts. The most common cause for this is having errors when building referenced projects.
Expand Down
Expand Up @@ -106,7 +106,7 @@ eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ })

Expand Down
Expand Up @@ -6,4 +6,10 @@
../lib/out/tsconfig.tsbuildinfo 70 KiB [emitted]
Entrypoint main = bundle.js
[./app.ts] 131 bytes {main} [built]
[./lib/out/index.js] 130 bytes {main}
[./lib/out/index.js] 130 bytes {main}

Asset Size Chunks Chunk Names
bundle.js 4.37 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 131 bytes {main}
[./lib/out/index.js] 161 bytes {main} [built]
Expand Up @@ -2,4 +2,4 @@
bundle.js 4.4 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 169 bytes {main} [built]
[./lib/out/index.js] 161 bytes {main} [built]
[./lib/out/index.js] 161 bytes {main}
Expand Up @@ -106,7 +106,7 @@ eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ })

Expand Down
Expand Up @@ -6,4 +6,10 @@
../lib/out/tsconfig.tsbuildinfo 70 KiB [emitted]
Entrypoint main = bundle.js
[./app.ts] 169 bytes {main} [built]
[./lib/out/index.js] 161 bytes {main}
[./lib/out/index.js] 161 bytes {main}

Asset Size Chunks Chunk Names
bundle.js 4.4 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 169 bytes {main}
[./lib/out/index.js] 156 bytes {main} [built]
Expand Up @@ -2,7 +2,7 @@
bundle.js 4.42 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 186 bytes {main} [built] [1 error]
[./lib/out/index.js] 156 bytes {main} [built]
[./lib/out/index.js] 156 bytes {main}

ERROR in app.ts
./app.ts
Expand Down
Expand Up @@ -94,19 +94,19 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ }),

/***/ "./lib/index.ts":
/*!**********************!*\
!*** ./lib/index.ts ***!
\**********************/
/***/ "./lib/out/index.js":
/*!**************************!*\
!*** ./lib/out/index.js ***!
\**************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ })

Expand Down
@@ -1,9 +1,5 @@
Asset Size Chunks Chunk Names
bundle.js 4.36 KiB main [emitted] main
../lib/out/index.js 169 bytes [emitted]
../lib/out/tsconfig.tsbuildinfo 70 KiB [emitted]
../lib/out/index.js.map 223 bytes [emitted]
../lib/out/index.d.ts 108 bytes [emitted]
Asset Size Chunks Chunk Names
bundle.js 4.4 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 167 bytes {main} [built]
[./lib/index.ts] 136 bytes {main} [built]
[./app.ts] 167 bytes {main}
[./lib/out/index.js] 161 bytes {main} [built]
Expand Up @@ -2,4 +2,4 @@
bundle.js 4.44 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 205 bytes {main} [built]
[./lib/out/index.js] 161 bytes {main} [built]
[./lib/out/index.js] 161 bytes {main}

This file was deleted.

Expand Up @@ -94,19 +94,19 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ }),

/***/ "./lib/index.ts":
/*!**********************!*\
!*** ./lib/index.ts ***!
\**********************/
/***/ "./lib/out/index.js":
/*!**************************!*\
!*** ./lib/out/index.js ***!
\**************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ })

Expand Down

0 comments on commit 9d62b44

Please sign in to comment.