Skip to content

Commit

Permalink
feat(karma-esm): use file watcher for reloading karma
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsDenBakker committed Aug 24, 2019
1 parent 1030dbc commit cf6346d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
1 change: 1 addition & 0 deletions packages/karma-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"es-dev-server": "^1.14.2",
"minimatch": "^3.0.4",
"portfinder": "^1.0.21",
"chokidar": "^3.0.2",
"request": "^2.88.0"
},
"devDependencies": {
Expand Down
13 changes: 6 additions & 7 deletions packages/karma-esm/src/esm-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
const request = require('request');
const minimatch = require('minimatch');
const portfinder = require('portfinder');
const { startServer, createConfig, messageChannelEndpoint } = require('es-dev-server');
const chokidar = require('chokidar');
const { startServer, createConfig } = require('es-dev-server');
const { createEsmConfig } = require('./esm-config.js');

async function setupDevServer(karmaConfig, esmConfig, watch, babelConfig, karmaEmitter) {
Expand All @@ -28,14 +29,12 @@ async function setupDevServer(karmaConfig, esmConfig, watch, babelConfig, karmaE
babelConfig,
});

await startServer(esDevServerConfig);
const fileWatcher = chokidar.watch([]);
await startServer(esDevServerConfig, fileWatcher);

if (watch) {
const messageChannel = request(`http://127.0.0.1:${devServerPort}${messageChannelEndpoint}`);
messageChannel.addListener('data', message => {
if (message.toString('utf-8').startsWith('event: file-changed')) {
karmaEmitter.refreshFiles();
}
fileWatcher.addListener('change', () => {
karmaEmitter.refreshFiles();
});
}

Expand Down
26 changes: 1 addition & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1991,30 +1991,6 @@
resolved "https://registry.yarnpkg.com/@open-wc/semantic-dom-diff/-/semantic-dom-diff-0.13.21.tgz#718b9ec5f9a98935fc775e577ad094ae8d8b7dea"
integrity sha512-BONpjHcGX2zFa9mfnwBCLEmlDsOHzT+j6Qt1yfK3MzFXFtAykfzFjAgaxPetu0YbBlCfXuMlfxI4vlRGCGMvFg==

"@open-wc/testing-karma-bs@file:./packages/testing-karma-bs":
version "1.1.48"
dependencies:
"@open-wc/testing-karma" "^3.1.23"
"@types/node" "^11.13.0"
karma-browserstack-launcher "^1.0.0"

"@open-wc/testing-karma@file:./packages/testing-karma":
version "3.1.23"
dependencies:
"@open-wc/karma-esm" "^2.4.2"
axe-core "^3.3.1"
istanbul-instrumenter-loader "^3.0.0"
karma "^4.0.0"
karma-chrome-launcher "^2.0.0"
karma-coverage-istanbul-reporter "^2.0.0"
karma-mocha "^1.0.0"
karma-mocha-reporter "^2.0.0"
karma-mocha-snapshot "^0.2.1"
karma-snapshot "^0.6.0"
karma-source-map-support "^1.3.0"
karma-sourcemap-loader "^0.3.0"
mocha "^6.2.0"

"@reach/router@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.2.1.tgz#34ae3541a5ac44fa7796e5506a5d7274a162be4e"
Expand Down Expand Up @@ -5273,7 +5249,7 @@ chokidar@^2.0.0, chokidar@^2.0.2, chokidar@^2.0.3, chokidar@^2.0.4, chokidar@^2.
optionalDependencies:
fsevents "^1.2.7"

chokidar@^3.0.0:
chokidar@^3.0.0, chokidar@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.0.2.tgz#0d1cd6d04eb2df0327446188cd13736a3367d681"
integrity sha512-c4PR2egjNjI1um6bamCQ6bUNPDiyofNQruHvKgHQ4gDUP/ITSVSzNsiI5OWtHOsX323i5ha/kk4YmOZ1Ktg7KA==
Expand Down

0 comments on commit cf6346d

Please sign in to comment.