forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-scripts.js
293 lines (290 loc) · 9.92 KB
/
package-scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
'use strict';
const path = require('path');
/**
* Generates a command to run mocha tests with or without test coverage
* as desired for the current runmode.
* @param {string} testName The name of the test to be used for coverage reporting.
* @param {string} mochaParams Parameters for the mocha CLI to execute the desired test.
* @returns {string} Command string to be executed by nps.
*/
function test(testName, mochaParams) {
const coverageCommand = `nyc --no-clean --report-dir coverage/reports/${testName}`;
const mochaCommand = `node ${path.join('bin', 'mocha')}`; // Include 'node' and path.join for Windows compatibility
if (process.env.CI && !/^only-/.test(testName)) {
mochaParams += ' --forbid-only';
}
return `${
process.env.COVERAGE ? coverageCommand : ''
} ${mochaCommand} ${mochaParams}`.trim();
}
module.exports = {
scripts: {
build: {
script: `browserify ./browser-entry --plugin ./scripts/dedefine --ignore 'fs' --ignore 'glob' --ignore 'path' --ignore 'supports-color' > mocha.js`,
description: 'Build browser bundle'
},
lint: {
default: {
script: 'nps lint.code lint.markdown',
description: 'Lint code and Markdown documentation'
},
code: {
script: 'eslint . "bin/*"',
description: 'Run ESLint linter'
},
markdown: {
script: 'markdownlint "*.md" "docs/**/*.md" ".github/*.md"',
description: 'Run markdownlint linter'
}
},
reformat: {
script:
'prettier-eslint --write "*.js" "lib/**/*.js" "test/**/*.js" "bin/*" "scripts/*"',
description: 'Reformat codebase with Prettier'
},
clean: {
script: 'rimraf mocha.js',
description: 'Clean browser bundle'
},
test: {
default: {
script: 'nps lint test.node test.browser test.bundle',
description: 'Run all linters and all tests'
},
node: {
default: {
script: `nps ${[
'build',
'test.node.bdd',
'test.node.tdd',
'test.node.qunit',
'test.node.exports',
'test.node.unit',
'test.node.integration',
'test.node.jsapi',
'test.node.requires',
'test.node.reporters',
'test.node.only',
'test.node.opts'
].join(' ')}`,
description: 'Run Node.js tests'
},
bdd: {
script: test('bdd', '--ui bdd test/interfaces/bdd.spec'),
description: 'Run Node.js BDD interface tests',
hiddenFromHelp: true
},
tdd: {
script: test('tdd', '--ui tdd test/interfaces/tdd.spec'),
description: 'Run Node.js TDD interface tests',
hiddenFromHelp: true
},
qunit: {
script: test('qunit', '--ui qunit test/interfaces/qunit.spec'),
description: 'Run Node.js QUnit interace tests',
hiddenFromHelp: true
},
exports: {
script: test('exports', '--ui exports test/interfaces/exports.spec'),
description: 'Run Node.js exports interface tests',
hiddenFromHelp: true
},
unit: {
script: test(
'unit',
'"test/unit/*.spec.js" "test/node-unit/**/*.spec.js" --growl'
),
description: 'Run Node.js unit tests'
},
integration: {
script: test(
'integration',
'--timeout 5000 --slow 1500 "test/integration/*.spec.js"'
),
description: 'Run Node.js integration tests',
hiddenFromHelp: true
},
opts: {
script: test(
'opts',
'--opts test/opts/mocha.opts test/opts/opts.spec.js --no-config'
),
description: 'Run tests concerning mocha.opts',
hiddenFromHelp: true
},
jsapi: {
script: 'node test/jsapi',
description: 'Run Node.js Mocha JavaScript API tests',
hiddenFromHelp: true
},
requires: {
script: test(
'requires',
[
'--require coffee-script/register',
'--require test/require/a.js',
'--require test/require/b.coffee',
'--require test/require/c.js',
'--require test/require/d.coffee',
'test/require/require.spec.js'
].join(' ')
),
description: 'Run Node.js --require flag tests',
hiddenFromHelp: true
},
reporters: {
script: test('reporters', '--timeout 500 "test/reporters/*.spec.js"'),
description: 'Run Node.js reporter tests',
hiddenFromHelp: true
},
only: {
default: {
script: `nps ${[
'test.node.only.bdd',
'test.node.only.tdd',
'test.node.only.bddRequire',
'test.node.only.globalBdd',
'test.node.only.globalTdd',
'test.node.only.globalQunit'
].join(' ')} `,
description: 'Run Node.js "only" functionality tests',
hiddenFromHelp: true
},
bdd: {
script: test('only-bdd', '--ui bdd test/only/bdd.spec'),
description: 'Run Node.js "only" w/ BDD interface tests',
hiddenFromHelp: true
},
tdd: {
script: test('only-tdd', '--ui tdd test/only/tdd.spec'),
description: 'Run Node.js "only" w/ TDD interface tests',
hiddenFromHelp: true
},
bddRequire: {
script: test(
'only-bdd-require',
'--ui qunit test/only/bdd-require.spec'
),
description: 'Run Node.js "only" w/ QUnit interface tests',
hiddenFromHelp: true
},
globalBdd: {
script: test(
'only-global-bdd',
'--ui bdd test/only/global/bdd.spec'
),
description: 'Run Node.js "global only" w/ BDD interface tests',
hiddenFromHelp: true
},
globalTdd: {
script: test(
'only-global-tdd',
'--ui tdd test/only/global/tdd.spec'
),
description: 'Run Node.js "global only" w/ TDD interface tests',
hiddenFromHelp: true
},
globalQunit: {
script: test(
'only-global-qunit',
'--ui qunit test/only/global/qunit.spec'
),
description: 'Run Node.js "global only" w/ QUnit interface tests',
hiddenFromHelp: true
}
}
},
browser: {
default: {
script:
'nps clean build test.browser.unit test.browser.bdd test.browser.tdd test.browser.qunit test.browser.esm',
description: 'Run browser tests'
},
unit: {
script: 'NODE_PATH=. karma start --single-run',
description: 'Run browser unit tests'
},
bdd: {
script: 'MOCHA_TEST=bdd nps test.browser.unit',
description: 'Run browser BDD interface tests',
hiddenFromHelp: true
},
tdd: {
script: 'MOCHA_TEST=tdd nps test.browser.unit',
description: 'Run browser TDD interface tests',
hiddenFromHelp: true
},
qunit: {
script: 'MOCHA_TEST=qunit nps test.browser.unit',
description: 'Run browser QUnit interface tests',
hiddenFromHelp: true
},
esm: {
script: 'MOCHA_TEST=esm nps test.browser.unit',
description: 'Run browser ES modules support test',
hiddenFromHelp: true
}
},
bundle: {
default: {
script: 'nps clean build test.bundle.amd',
description: 'Run bundle-related tests'
},
amd: {
script: test('amd', 'test/bundle/amd.spec'),
description: 'Run AMD bundle tests',
hiddenFromHelp: true
}
}
},
coveralls: {
script: 'nyc report --reporter=text-lcov | coveralls',
description: 'Send code coverage report to coveralls (run during CI)',
hiddenFromHelp: true
},
'coverage-report': {
script: 'nyc report --reporter=html',
description:
'Output HTML coverage report to coverage/index.html (run tests with COVERAGE=1 first)'
},
docs: {
default: {
script:
'nps docs.prebuild && bundle exec jekyll build --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts && nps docs.postbuild',
description: 'Build documentation'
},
prebuild: {
script:
'rimraf docs/_dist docs/api && nps docs.preprocess && nps docs.api',
description: 'Prepare system for doc building',
hiddenFromHelp: true
},
postbuild: {
script:
'buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js >> docs/_dist/_headers',
description: 'Post-process docs after build',
hiddenFromHelp: true
},
preprocess: {
script:
'md-magic --config ./scripts/markdown-magic.config.js --path docs/index.md',
description: 'Preprocess documenation',
hiddenFromHelp: true
},
watch: {
script:
'nps docs.preprocess && bundle exec jekyll serve --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts --watch',
description: 'Watch docs for changes & build'
},
api: {
script:
'mkdirp docs/api && jsdoc -c jsdoc.conf.json && cp LICENSE docs/api',
description: 'build api docs'
}
},
updateContributors: {
script: 'node scripts/update-contributors.js',
description: 'Update list of contributors in package.json'
}
}
};