Skip to content

Commit 2b72fd0

Browse files
authored
fix: properly disconnect rpc client to be able to reconnect (#439)
Closes: #438
1 parent c4796b2 commit 2b72fd0

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

src/reporter/reporter-rpc/ReporterRpcClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ function createReporterRpcClient<TConfiguration extends object>(
2727
}
2828
},
2929
disconnect: async () => {
30-
if (channel.isOpen()) {
31-
await channel.close();
32-
}
3330
if (rpcClient.isConnected()) {
3431
await rpcClient.disconnect();
3532
}
33+
if (channel.isOpen()) {
34+
await channel.close();
35+
}
3636
},
3737
getReport: async (change) => await rpcClient.dispatchCall(getIssues, change),
3838
};

test/e2e/WebpackNodeApi.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { createSandbox, FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION, Sandbox } from './sandbox/Sandbox';
2+
import { readFixture } from './sandbox/Fixture';
3+
import { join } from 'path';
4+
import { WEBPACK_CLI_VERSION, WEBPACK_DEV_SERVER_VERSION } from './sandbox/WebpackDevServerDriver';
5+
6+
describe('Webpack Node Api', () => {
7+
let sandbox: Sandbox;
8+
9+
beforeAll(async () => {
10+
sandbox = await createSandbox();
11+
});
12+
13+
beforeEach(async () => {
14+
await sandbox.reset();
15+
});
16+
17+
afterAll(async () => {
18+
await sandbox.cleanup();
19+
});
20+
21+
it.each([{ webpack: '4.0.0' }, { webpack: '^4.0.0' }, { webpack: '^5.0.0-beta.16' }])(
22+
'compiles the project successfully with %p',
23+
async ({ webpack }) => {
24+
await sandbox.load([
25+
await readFixture(join(__dirname, 'fixtures/environment/typescript-basic.fixture'), {
26+
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
27+
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
28+
),
29+
TS_LOADER_VERSION: JSON.stringify('^5.0.0'),
30+
TYPESCRIPT_VERSION: JSON.stringify('~3.8.0'),
31+
WEBPACK_VERSION: JSON.stringify(webpack),
32+
WEBPACK_CLI_VERSION: JSON.stringify(WEBPACK_CLI_VERSION),
33+
WEBPACK_DEV_SERVER_VERSION: JSON.stringify(WEBPACK_DEV_SERVER_VERSION),
34+
ASYNC: JSON.stringify(false),
35+
}),
36+
await readFixture(join(__dirname, 'fixtures/implementation/typescript-basic.fixture')),
37+
await readFixture(join(__dirname, 'fixtures/implementation/webpack-node-api.fixture')),
38+
]);
39+
40+
const result = await sandbox.exec('node ./webpack-node-api.js');
41+
expect(result).toContain('Compiled successfully twice.');
42+
}
43+
);
44+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// webpack-node-api.js
2+
const webpack = require("webpack");
3+
const configuration = require("./webpack.config.js");
4+
5+
const builder = webpack({ ...configuration, mode: 'development' });
6+
7+
function run() {
8+
return new Promise((resolve, reject) => {
9+
builder.run((error, stats) => {
10+
if (error) {
11+
reject(error);
12+
} else {
13+
resolve(stats);
14+
}
15+
});
16+
});
17+
}
18+
19+
function runAndPrint() {
20+
return run()
21+
.then((stats) => {
22+
const warnings = stats.compilation.warnings;
23+
const errors = stats.compilation.errors;
24+
25+
if (warnings.length === 0 && errors.length === 0) {
26+
console.log('Compiled successfully.')
27+
} else {
28+
console.log('Compiled with warnings or errors.');
29+
}
30+
})
31+
.catch((error) => console.error(error));
32+
}
33+
34+
// run build twice in sequence
35+
runAndPrint()
36+
.then(() => runAndPrint())
37+
.then(() => console.log('Compiled successfully twice.'));

0 commit comments

Comments
 (0)