Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Commit 867efca

Browse files
committed
Remove deasync from integration tests and use async/await instead
1 parent 76590e0 commit 867efca

File tree

4 files changed

+82
-43
lines changed

4 files changed

+82
-43
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["transform-async-to-generator"]
3+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"babel-core": "^6.23.1",
3131
"babel-eslint": "^7.1.1",
3232
"babel-loader": "^6.3.0",
33+
"babel-plugin-transform-async-to-generator": "^6.22.0",
3334
"babel-preset-react": "^6.23.0",
34-
"deasync": "^0.1.9",
3535
"eslint": "^3.15.0",
3636
"eslint-loader": "^1.6.1",
3737
"expect": "^1.20.2",
@@ -43,4 +43,4 @@
4343
"chalk": "^1.1.3",
4444
"error-stack-parser": "^2.0.0"
4545
}
46-
}
46+
}

test/integration.spec.js

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
const output = require('../src/output');
2-
const deasync = require('deasync');
32
const webpack = require('webpack');
43
const FriendlyErrorsWebpackPlugin = require('../src/friendly-errors-plugin');
54
const MemoryFileSystem = require('memory-fs');
65

7-
const syncWebpack = deasync(function(config, fn) {
6+
const webpackPromise = function(config, ...globalPlugins) {
87
const compiler = webpack(config);
98
compiler.outputFileSystem = new MemoryFileSystem();
10-
compiler.run(fn);
11-
return compiler;
12-
});
9+
globalPlugins.forEach(p => compiler.apply(p));
10+
11+
return new Promise((resolve, reject) => {
12+
compiler.run(err => {
13+
if (err) {
14+
reject(err)
15+
}
16+
resolve()
17+
});
18+
});
19+
};
1320

14-
// Applys plugin directly to compiler to support `MultiCompiler` tests.
15-
const syncWebpackWithPlugin = deasync(function(config, fn) {
16-
const compiler = webpack(config);
17-
compiler.outputFileSystem = new MemoryFileSystem();
18-
compiler.apply(new FriendlyErrorsWebpackPlugin());
19-
compiler.run(fn);
20-
return compiler;
21-
});
21+
async function executeAndGetLogs(fixture, ...globalPlugins) {
22+
try {
23+
output.capture();
24+
await webpackPromise(require(fixture), ...globalPlugins);
25+
return output.capturedMessages;
26+
} finally {
27+
output.endCapture()
28+
}
29+
}
2230

23-
it('integration : success', () => {
31+
it('integration : success', async () => {
2432

25-
const logs = output.captureLogs(() => {
26-
syncWebpack(require('./fixtures/success/webpack.config'));
27-
});
33+
const logs = await executeAndGetLogs('./fixtures/success/webpack.config')
2834

2935
expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/);
3036
});
3137

38+
it('integration : module-errors', async () => {
3239

33-
it('integration : module-errors', () => {
34-
35-
const logs = output.captureLogs(() => {
36-
syncWebpack(require('./fixtures/module-errors/webpack.config.js'));
37-
});
40+
const logs = await executeAndGetLogs('./fixtures/module-errors/webpack.config.js');
3841

3942
expect(logs).toEqual([
4043
' ERROR Failed to compile with 2 errors',
@@ -48,11 +51,9 @@ it('integration : module-errors', () => {
4851
]);
4952
});
5053

51-
it('integration : should display eslint warnings', () => {
54+
it('integration : should display eslint warnings', async () => {
5255

53-
const logs = output.captureLogs(() => {
54-
syncWebpack(require('./fixtures/eslint-warnings/webpack.config.js'));
55-
});
56+
const logs = await executeAndGetLogs('./fixtures/eslint-warnings/webpack.config.js');
5657

5758
expect(logs).toEqual([
5859
' WARNING Compiled with 1 warnings',
@@ -71,11 +72,9 @@ it('integration : should display eslint warnings', () => {
7172
]);
7273
});
7374

74-
it('integration : babel syntax error', () => {
75+
it('integration : babel syntax error', async () => {
7576

76-
const logs = output.captureLogs(() => {
77-
syncWebpack(require('./fixtures/babel-syntax/webpack.config'));
78-
});
77+
const logs = await executeAndGetLogs('./fixtures/babel-syntax/webpack.config');
7978

8079
expect(logs).toEqual([
8180
' ERROR Failed to compile with 1 errors',
@@ -94,20 +93,18 @@ it('integration : babel syntax error', () => {
9493
]);
9594
});
9695

97-
it('integration : webpack multi compiler : success', () => {
96+
it('integration : webpack multi compiler : success', async () => {
9897

99-
const logs = output.captureLogs(() => {
100-
syncWebpackWithPlugin(require('./fixtures/multi-compiler-success/webpack.config'));
101-
});
98+
// We apply the plugin directly to the compiler when targeting multi-compiler
99+
const logs = await executeAndGetLogs('./fixtures/multi-compiler-success/webpack.config', new FriendlyErrorsWebpackPlugin());
102100

103101
expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/)
104102
});
105103

106-
it('integration : webpack multi compiler : module-errors', () => {
104+
it('integration : webpack multi compiler : module-errors', async () => {
107105

108-
const logs = output.captureLogs(() => {
109-
syncWebpackWithPlugin(require('./fixtures/multi-compiler-module-errors/webpack.config'));
110-
});
106+
// We apply the plugin directly to the compiler when targeting multi-compiler
107+
const logs = await executeAndGetLogs('./fixtures/multi-compiler-module-errors/webpack.config', new FriendlyErrorsWebpackPlugin());
111108

112109
expect(logs).toEqual([
113110
' ERROR Failed to compile with 2 errors',

yarn.lock

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,33 @@ babel-helper-builder-react-jsx@^6.23.0:
263263
esutils "^2.0.0"
264264
lodash "^4.2.0"
265265

266+
babel-helper-function-name@^6.22.0:
267+
version "6.23.0"
268+
resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.23.0.tgz#25742d67175c8903dbe4b6cb9d9e1fcb8dcf23a6"
269+
dependencies:
270+
babel-helper-get-function-arity "^6.22.0"
271+
babel-runtime "^6.22.0"
272+
babel-template "^6.23.0"
273+
babel-traverse "^6.23.0"
274+
babel-types "^6.23.0"
275+
276+
babel-helper-get-function-arity@^6.22.0:
277+
version "6.22.0"
278+
resolved "https://registry.yarnpkg.com/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.22.0.tgz#0beb464ad69dc7347410ac6ade9f03a50634f5ce"
279+
dependencies:
280+
babel-runtime "^6.22.0"
281+
babel-types "^6.22.0"
282+
283+
babel-helper-remap-async-to-generator@^6.22.0:
284+
version "6.22.0"
285+
resolved "https://registry.yarnpkg.com/babel-helper-remap-async-to-generator/-/babel-helper-remap-async-to-generator-6.22.0.tgz#2186ae73278ed03b8b15ced089609da981053383"
286+
dependencies:
287+
babel-helper-function-name "^6.22.0"
288+
babel-runtime "^6.22.0"
289+
babel-template "^6.22.0"
290+
babel-traverse "^6.22.0"
291+
babel-types "^6.22.0"
292+
266293
babel-helpers@^6.23.0:
267294
version "6.23.0"
268295
resolved "https://registry.yarnpkg.com/babel-helpers/-/babel-helpers-6.23.0.tgz#4f8f2e092d0b6a8808a4bde79c27f1e2ecf0d992"
@@ -306,6 +333,10 @@ babel-plugin-jest-hoist@^18.0.0:
306333
version "18.0.0"
307334
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-18.0.0.tgz#4150e70ecab560e6e7344adc849498072d34e12a"
308335

336+
babel-plugin-syntax-async-functions@^6.8.0:
337+
version "6.13.0"
338+
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
339+
309340
babel-plugin-syntax-flow@^6.18.0:
310341
version "6.18.0"
311342
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d"
@@ -314,6 +345,14 @@ babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
314345
version "6.13.0"
315346
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.13.0.tgz#e741ff3992c578310be45c571bcd90a2f9c5586e"
316347

348+
babel-plugin-transform-async-to-generator@^6.22.0:
349+
version "6.22.0"
350+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.22.0.tgz#194b6938ec195ad36efc4c33a971acf00d8cd35e"
351+
dependencies:
352+
babel-helper-remap-async-to-generator "^6.22.0"
353+
babel-plugin-syntax-async-functions "^6.8.0"
354+
babel-runtime "^6.22.0"
355+
317356
babel-plugin-transform-flow-strip-types@^6.22.0:
318357
version "6.22.0"
319358
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf"
@@ -391,7 +430,7 @@ babel-runtime@^6.22.0:
391430
core-js "^2.4.0"
392431
regenerator-runtime "^0.10.0"
393432

394-
babel-template@^6.16.0, babel-template@^6.23.0:
433+
babel-template@^6.16.0, babel-template@^6.22.0, babel-template@^6.23.0:
395434
version "6.23.0"
396435
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.23.0.tgz#04d4f270adbb3aa704a8143ae26faa529238e638"
397436
dependencies:
@@ -401,7 +440,7 @@ babel-template@^6.16.0, babel-template@^6.23.0:
401440
babylon "^6.11.0"
402441
lodash "^4.2.0"
403442

404-
babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.23.0, babel-traverse@^6.23.1:
443+
babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.22.0, babel-traverse@^6.23.0, babel-traverse@^6.23.1:
405444
version "6.23.1"
406445
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.23.1.tgz#d3cb59010ecd06a97d81310065f966b699e14f48"
407446
dependencies:
@@ -415,7 +454,7 @@ babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.23.0, babel-tr
415454
invariant "^2.2.0"
416455
lodash "^4.2.0"
417456

418-
babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.23.0:
457+
babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.22.0, babel-types@^6.23.0:
419458
version "6.23.0"
420459
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.23.0.tgz#bb17179d7538bad38cd0c9e115d340f77e7e9acf"
421460
dependencies:

0 commit comments

Comments
 (0)