Skip to content

Commit cbb92ce

Browse files
authored
Merge pull request #28 from trash/master
Service is killed when webpack watch is done
2 parents 49d8bde + ac6cf00 commit cbb92ce

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
146146
};
147147

148148
ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
149+
this.compiler.plugin('watch-close', function () {
150+
this.killService();
151+
}.bind(this));
152+
149153
this.compiler.plugin('done', function () {
150154
if (!this.isWatching) {
151155
this.killService();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"peerDependencies": {
5757
"typescript": "^2.1.0",
58-
"webpack": "^2.0.0 || ^3.0.0"
58+
"webpack": "^2.3.0 || ^3.0.0"
5959
},
6060
"dependencies": {
6161
"babel-code-frame": "^6.22.0",

test/integration/index.spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ var ForkTsCheckerWebpackPlugin = require('../../lib/index');
88

99
describe('[INTEGRATION] index', function () {
1010
this.timeout(30000);
11+
var plugin;
1112

1213
function createCompiler(options) {
14+
plugin = new ForkTsCheckerWebpackPlugin(Object.assign({}, options, { silent: true }));
15+
1316
return webpack({
1417
context: path.resolve(__dirname, './project'),
1518
entry: './src/index.ts',
@@ -29,11 +32,20 @@ describe('[INTEGRATION] index', function () {
2932
]
3033
},
3134
plugins: [
32-
new ForkTsCheckerWebpackPlugin(Object.assign({}, options, { silent: true }))
35+
plugin
3336
]
3437
});
3538
}
3639

40+
/**
41+
* Implicitly check whether killService was called by checking that
42+
* the service property was set to undefined.
43+
* @returns [boolean] true if killService was called
44+
*/
45+
function killServiceWasCalled() {
46+
return plugin.service === undefined;
47+
}
48+
3749
it('should allow to pass no options', function () {
3850
expect(function () {
3951
new ForkTsCheckerWebpackPlugin();
@@ -108,6 +120,18 @@ describe('[INTEGRATION] index', function () {
108120
});
109121
});
110122

123+
it('kills the service when the watch is done', function (done) {
124+
var compiler = createCompiler();
125+
var watching = compiler.watch({}, function() {});
126+
127+
compiler.plugin('fork-ts-checker-done', function () {
128+
watching.close(function() {
129+
expect(killServiceWasCalled()).to.be.true;
130+
done();
131+
});
132+
});
133+
});
134+
111135
it('should throw error if config container wrong tsconfig.json path', function () {
112136
expect(function() {
113137
createCompiler({

0 commit comments

Comments
 (0)