Skip to content

Commit

Permalink
fix: properly disconnect rpc client to be able to reconnect (#439)
Browse files Browse the repository at this point in the history
Closes: #438
  • Loading branch information
piotr-oles committed Jun 5, 2020
1 parent c4796b2 commit 2b72fd0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/reporter/reporter-rpc/ReporterRpcClient.ts
Expand Up @@ -27,12 +27,12 @@ function createReporterRpcClient<TConfiguration extends object>(
}
},
disconnect: async () => {
if (channel.isOpen()) {
await channel.close();
}
if (rpcClient.isConnected()) {
await rpcClient.disconnect();
}
if (channel.isOpen()) {
await channel.close();
}
},
getReport: async (change) => await rpcClient.dispatchCall(getIssues, change),
};
Expand Down
44 changes: 44 additions & 0 deletions test/e2e/WebpackNodeApi.spec.ts
@@ -0,0 +1,44 @@
import { createSandbox, FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION, Sandbox } from './sandbox/Sandbox';
import { readFixture } from './sandbox/Fixture';
import { join } from 'path';
import { WEBPACK_CLI_VERSION, WEBPACK_DEV_SERVER_VERSION } from './sandbox/WebpackDevServerDriver';

describe('Webpack Node Api', () => {
let sandbox: Sandbox;

beforeAll(async () => {
sandbox = await createSandbox();
});

beforeEach(async () => {
await sandbox.reset();
});

afterAll(async () => {
await sandbox.cleanup();
});

it.each([{ webpack: '4.0.0' }, { webpack: '^4.0.0' }, { webpack: '^5.0.0-beta.16' }])(
'compiles the project successfully with %p',
async ({ webpack }) => {
await sandbox.load([
await readFixture(join(__dirname, 'fixtures/environment/typescript-basic.fixture'), {
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
),
TS_LOADER_VERSION: JSON.stringify('^5.0.0'),
TYPESCRIPT_VERSION: JSON.stringify('~3.8.0'),
WEBPACK_VERSION: JSON.stringify(webpack),
WEBPACK_CLI_VERSION: JSON.stringify(WEBPACK_CLI_VERSION),
WEBPACK_DEV_SERVER_VERSION: JSON.stringify(WEBPACK_DEV_SERVER_VERSION),
ASYNC: JSON.stringify(false),
}),
await readFixture(join(__dirname, 'fixtures/implementation/typescript-basic.fixture')),
await readFixture(join(__dirname, 'fixtures/implementation/webpack-node-api.fixture')),
]);

const result = await sandbox.exec('node ./webpack-node-api.js');
expect(result).toContain('Compiled successfully twice.');
}
);
});
37 changes: 37 additions & 0 deletions test/e2e/fixtures/implementation/webpack-node-api.fixture
@@ -0,0 +1,37 @@
/// webpack-node-api.js
const webpack = require("webpack");
const configuration = require("./webpack.config.js");

const builder = webpack({ ...configuration, mode: 'development' });

function run() {
return new Promise((resolve, reject) => {
builder.run((error, stats) => {
if (error) {
reject(error);
} else {
resolve(stats);
}
});
});
}

function runAndPrint() {
return run()
.then((stats) => {
const warnings = stats.compilation.warnings;
const errors = stats.compilation.errors;

if (warnings.length === 0 && errors.length === 0) {
console.log('Compiled successfully.')
} else {
console.log('Compiled with warnings or errors.');
}
})
.catch((error) => console.error(error));
}

// run build twice in sequence
runAndPrint()
.then(() => runAndPrint())
.then(() => console.log('Compiled successfully twice.'));

0 comments on commit 2b72fd0

Please sign in to comment.