Skip to content

Commit a5407d4

Browse files
authored
Merge 62b7474 into c22c297
2 parents c22c297 + 62b7474 commit a5407d4

File tree

12 files changed

+5558
-94
lines changed

12 files changed

+5558
-94
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
node_modules
22
npm-debug.log
3-
static/context.js
4-
static/karma.js
53
.idea/*
64
*.iml
75
docs/_build

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ jobs:
77
- node_js: "10"
88
script:
99
- npm run init
10-
- npm run build
1110
- npm run test:unit
1211
- npm run test:e2e
1312

1413
- node_js: "12"
1514
script:
1615
- npm run init
17-
- npm run build
1816
- npm run test:unit
1917
- npm run test:e2e
2018

@@ -23,7 +21,7 @@ jobs:
2321
- npm run init
2422
- commitlint-travis
2523
- npm run lint
26-
- npm run build
24+
- npm run build:check
2725
- npm run test:unit
2826
- npm run test:e2e
2927
- npm run test:client

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install:
2424
- npm run init:windows
2525

2626
test_script:
27-
- npm run appveyor
27+
- npm run test:appveyor
2828

2929
build: off
3030

docs/dev/02-making-changes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Here are some tips on how to set up a Karma workspace and how to send a good pul
2727
$ npm run init
2828
# or if you're on Windows
2929
$ npm run init:windows
30-
31-
$ npm run build
3230
```
3331

3432
## Testing and Building

lib/server.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const tmp = require('tmp')
88
const fs = require('fs')
99
const path = require('path')
1010

11-
const BundleUtils = require('./utils/bundle-utils')
1211
const NetUtils = require('./utils/net-utils')
1312
const root = global || window || this
1413

@@ -116,10 +115,6 @@ class Server extends KarmaEventEmitter {
116115
async start () {
117116
const config = this.get('config')
118117
try {
119-
await Promise.all([
120-
BundleUtils.bundleResourceIfNotExist('client/main.js', 'static/karma.js'),
121-
BundleUtils.bundleResourceIfNotExist('context/main.js', 'static/context.js')
122-
])
123118
this._boundServer = await NetUtils.bindAvailablePort(config.port, config.listenAddress)
124119
this._boundServer.on('connection', (socket) => {
125120
// Attach an error handler to avoid UncaughtException errors.

lib/utils/bundle-utils.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,14 @@
491491
"test:e2e": "cucumber-js test/e2e/*.feature",
492492
"test:client": "grunt test:client",
493493
"test": "npm run test:unit && npm run test:e2e && npm run test:client",
494-
"build": "grunt build",
494+
"build": "node scripts/client.js build",
495+
"build:check": "node scripts/client.js check",
495496
"test:appveyor": "grunt test-appveyor",
496497
"test:integration": "./scripts/integration-tests.sh",
497498
"link": "node --eval \"path=require('path'); require('fs').symlinkSync(path.resolve(__dirname), path.resolve(__dirname, 'node_modules', 'karma'), 'junction')\"",
498499
"unlink": "node --eval \"require('fs').unlinkSync(require('path').resolve(__dirname, 'node_modules', 'karma'))\"",
499500
"init": "rm -rf node_modules/karma && cd node_modules && ln -nsf ../ karma && cd ../",
500501
"init:windows": "(IF EXIST node_modules\\karma (rmdir node_modules\\karma /S /q)) && npm run link",
501-
"appveyor": "npm run build && npm run test:appveyor",
502502
"semantic-release": "semantic-release"
503503
}
504504
}

scripts/client.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const browserify = require('browserify')
2+
const fs = require('fs')
3+
const { readFile } = require('fs').promises
4+
5+
const bundleResourceToFile = (inPath, outPath) => {
6+
return new Promise((resolve, reject) => {
7+
browserify(inPath).bundle()
8+
.pipe(fs.createWriteStream(outPath))
9+
.once('finish', () => resolve())
10+
.once('error', (e) => reject(e))
11+
})
12+
}
13+
14+
const bundleResource = (inPath) => {
15+
return new Promise((resolve, reject) => {
16+
browserify(inPath).bundle((err, buffer) => {
17+
if (err != null) {
18+
reject(err)
19+
return
20+
}
21+
22+
resolve(buffer)
23+
})
24+
})
25+
}
26+
27+
const main = async () => {
28+
if (process.argv[2] === 'build') {
29+
await bundleResourceToFile('client/main.js', 'static/karma.js')
30+
await bundleResourceToFile('context/main.js', 'static/context.js')
31+
} else if (process.argv[2] === 'check') {
32+
const expectedClient = await bundleResource('client/main.js')
33+
const expectedContext = await bundleResource('context/main.js')
34+
35+
const actualClient = await readFile('static/karma.js')
36+
const actualContext = await readFile('static/context.js')
37+
38+
if (Buffer.compare(expectedClient, actualClient) !== 0 || Buffer.compare(expectedContext, actualContext) !== 0) {
39+
// eslint-disable-next-line no-throw-literal
40+
throw 'Bundled client assets are outdated. Forgot to run "npm run build"?'
41+
}
42+
} else {
43+
// eslint-disable-next-line no-throw-literal
44+
throw `Unknown command: ${process.argv[2]}`
45+
}
46+
}
47+
48+
main().catch((err) => {
49+
console.error(err)
50+
process.exit(1)
51+
})

0 commit comments

Comments
 (0)