-
Notifications
You must be signed in to change notification settings - Fork 781
/
Gruntfile.js
180 lines (161 loc) · 5.26 KB
/
Gruntfile.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
/* eslint-env node */
'use strict';
const fs = require('fs');
const path = require('path');
const { preprocess } = require('./build/dist-replace.js');
let isCI = process.env.CI;
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-search');
grunt.initConfig({
connect: {
base: {
options: {
useAvailablePort: true,
base: '.'
}
}
},
copy: {
options: { process: preprocess },
'src-css': {
src: 'src/core/qunit.css',
dest: 'qunit/qunit.css'
},
'src-export-cjs-wrappers': {
src: 'src/core/qunit-wrapper-bundler-require.js',
expand: true,
flatten: true,
dest: 'qunit/'
},
'src-export-esm-wrappers': {
src: 'src/core/qunit-wrapper-nodejs-module.js',
expand: true,
flatten: true,
dest: 'qunit/esm/'
}
},
search: {
options: {
// Ensure that the only HTML entities used are those with a special status in XHTML
// and that any common singleton/empty HTML elements end with the XHTML-compliant
// "/>"rather than ">"
searchString: /(&(?!gt|lt|amp|quot)[A-Za-z0-9]+;|<(?:hr|HR|br|BR|input|INPUT)(?![^>]*\/>)(?:\s+[^>]*)?>)/g,
logFormat: 'console',
failOnMatch: true
},
xhtml: [
'src/**/*.js'
]
},
qunit: {
options: {
timeout: 30000,
console: false,
puppeteer: {
args: isCI
// For CI
? ['--no-sandbox']
// For local development
// Allow Docker-based developer environmment to
// inject --no-sandbox as-needed for Chrome.
: (process.env.CHROMIUM_FLAGS || '').split(' ')
},
inject: [
path.resolve('./build/coverage-bridge.js'),
require.resolve('grunt-contrib-qunit/chrome/bridge')
]
},
// @HTML_FILES
all: [
'test/index.html',
'test/config-reporters.html',
'test/dynamic-import.html',
'test/events-filters.html',
'test/events-in-test.html',
'test/index-es5.html',
'test/index-xhtml.xhtml',
'test/logs.html',
'test/module-skip.html',
'test/module-todo.html',
'test/only-each.html',
'test/overload.html',
'test/performance-mark.html',
'test/preconfig-flat-reporters.html',
'test/preconfig-flat-testId.html',
'test/preconfig-flat.html',
'test/preconfig-object.html',
'test/reorder.html',
'test/reorderError1.html',
'test/reorderError2.html',
'test/reporter-urlparams.html',
'test/sandboxed-iframe.html',
'test/seed.html',
'test/startError.html',
'test/urlparams-filter.html',
'test/urlparams-module.html',
'test/urlparams-moduleId.html',
'test/urlparams-testId.html',
'test/webWorker.html',
'demos/q4000-qunit.html',
'test/browser-runner/amd.html',
'test/browser-runner/autostart.html',
'test/browser-runner/config-fixture-null.html',
'test/browser-runner/config-fixture-string.html',
'test/browser-runner/headless.html',
'test/browser-runner/window-onerror-preexisting-handler.html',
'test/browser-runner/window-onerror.html'
]
},
'test-on-node': {
files: [
// Sync with test/index.html
'test/main/assert.js',
'test/main/assert-es6.js',
'test/main/assert-step.js',
'test/main/assert-timeout.js',
'test/main/async.js',
'test/main/browser-runner.js',
'test/main/callbacks.js',
'test/main/deepEqual.js',
'test/main/diff.js',
'test/main/dump.js',
'test/main/each.js',
'test/main/events.js',
'test/main/HtmlReporter.js',
'test/main/modules.js',
'test/main/modules-es2018.js',
'test/main/modules-esm.mjs',
'test/main/legacy.js',
'test/main/onUncaughtException.js',
'test/main/promise.js',
'test/main/setTimeout.js',
'test/main/stacktrace.js',
'test/main/TapReporter.js',
'test/main/test.js',
'test/main/utilities.js',
// Sync with test/*.html files that also make sense for Node.js
'test/events-in-test.js',
'test/logs.js',
'test/module-skip.js',
'test/module-todo.js',
'test/node/storage-1.js',
'test/node/storage-2.js'
]
}
});
grunt.event.once('connect.base.listening', function (_host, port) {
grunt.config('qunit.options.httpBase', `http://localhost:${port}`);
// console.log(grunt.config()); // DEBUG
});
grunt.event.on('qunit.coverage', function (file, coverage) {
let testName = file.split('/test/').pop().replace('.html', '').replace(/[/\\]/g, '--');
let reportPath = path.join('.nyc_output', 'browser--' + testName + '.json');
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
fs.writeFileSync(reportPath, JSON.stringify(coverage) + '\n');
});
grunt.loadTasks('build/tasks');
grunt.registerTask('test', ['search', 'test-on-node', 'connect:base', 'qunit']);
};