forked from qunitjs/qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
223 lines (205 loc) · 5.86 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
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
/* eslint-env node */
const fs = require( "fs" );
const path = require( "path" );
const { preprocess } = require( "./build/dist-replace.js" );
// Detect Travis CI or Jenkins.
var isCI = process.env.CI || process.env.JENKINS_HOME;
module.exports = function( grunt ) {
var livereloadPort = grunt.option( "livereload-port" ) || 35729;
var connectPort = Number( grunt.option( "connect-port" ) ) || 4000;
// Load grunt tasks from NPM packages
grunt.loadNpmTasks( "grunt-contrib-connect" );
grunt.loadNpmTasks( "grunt-contrib-copy" );
grunt.loadNpmTasks( "grunt-contrib-qunit" );
grunt.loadNpmTasks( "grunt-contrib-watch" );
grunt.loadNpmTasks( "grunt-eslint" );
grunt.loadNpmTasks( "grunt-search" );
grunt.initConfig( {
connect: {
nolivereload: {
options: {
// grunt-contrib-connect supports 'useAvailablePort' which
// automatically finds a suitable port, but we can't use that here because
// the grunt-contrib-qunit task needs to know the url ahead of time.
port: connectPort,
base: "."
}
},
// For manual testing.
any: {
options: {
port: connectPort,
useAvailablePort: true,
keepalive: true,
base: "."
}
},
// For use by the "watch" task.
livereload: {
options: {
port: connectPort,
base: ".",
livereload: livereloadPort
}
}
},
copy: {
options: { process: preprocess },
"src-css": {
src: "src/qunit.css",
dest: "dist/qunit.css"
}
},
eslint: {
js: ".",
html: {
options: {
rules: {
indent: "off"
}
},
src: [
// Linting HTML files via eslint-plugin-html
"test/**/*.html"
]
}
},
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, // eslint-disable-line max-len
logFormat: "console",
failOnMatch: true
},
xhtml: [
"src/**/*.js",
"reporter/**/*.js"
]
},
qunit: {
all: {
options: {
timeout: 30000,
puppeteer: !isCI ? {
// Allow Docker-based developer environmment to
// inject --no-sandbox as-needed for Chrome.
args: ( process.env.CHROMIUM_FLAGS || "" ).split( " " )
} : {
args: [
// https://docs.travis-ci.com/user/chrome#sandboxing
"--no-sandbox"
]
},
inject: [
path.resolve( "./build/coverage-bridge.js" ),
require.resolve( "grunt-contrib-qunit/chrome/bridge" )
],
urls: [
"test/sandboxed-iframe.html",
"test/index.html",
"test/autostart.html",
"test/startError.html",
"test/reorder.html",
"test/reorderError1.html",
"test/reorderError2.html",
"test/callbacks.html",
"test/callbacks-promises.html",
"test/events.html",
"test/events-in-test.html",
"test/logs.html",
"test/setTimeout.html",
"test/amd.html",
"test/reporter-html/legacy-markup.html",
"test/reporter-html/no-qunit-element.html",
"test/reporter-html/single-testid.html",
"test/reporter-html/window-onerror.html",
"test/reporter-html/window-onerror-preexisting-handler.html",
"test/reporter-html/xhtml-escape-details-source.xhtml",
"test/reporter-html/xhtml-single-testid.xhtml",
"test/reporter-urlparams.html",
"test/reporter-urlparams-hidepassed.html",
"test/moduleId.html",
"test/onerror/inside-test.html",
"test/onerror/outside-test.html",
"test/only.html",
"test/seed.html",
"test/overload.html",
"test/preconfigured.html",
"test/regex-filter.html",
"test/regex-exclude-filter.html",
"test/string-filter.html",
"test/module-only.html",
"test/module-skip.html",
"test/module-todo.html"
].map( file => `http://localhost:${connectPort}/${file}` )
}
}
},
"test-on-node": {
files: [
"test/logs",
"test/main/test",
"test/main/assert",
"test/main/assert/step",
"test/main/assert/timeout",
"test/main/async",
"test/main/promise",
"test/main/modules",
"test/main/deepEqual",
"test/main/stack",
"test/main/utilities",
"test/events",
"test/events-in-test",
"test/onerror/inside-test",
"test/onerror/outside-test",
"test/only",
"test/setTimeout",
"test/main/dump",
"test/node/storage-1",
"test/node/storage-2",
"test/module-only",
"test/module-skip",
"test/module-todo",
"test/es2017/async-functions"
]
},
"watch-repeatable": {
options: {
atBegin: true,
spawn: false,
interrupt: true
},
files: [
".eslintrc.json",
"*.js",
"build/*.js",
"{src,test,reporter}/**/*.js",
"src/qunit.css",
"test/*.{html,js}",
"test/**/*.html"
],
tasks: [ "build", "livereload", "test-in-watch" ]
},
livereload: {
options: {
port: livereloadPort
}
}
} );
grunt.event.on( "qunit.coverage", function( file, coverage ) {
var testName = file.split( "/test/" ).pop().replace( ".html", "" ).replace( /[/\\]/g, "--" );
var 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-base", [ "eslint", "search", "test-on-node" ] );
grunt.registerTask( "test", [ "test-base", "connect:nolivereload", "qunit" ] );
grunt.registerTask( "test-in-watch", [ "test-base", "qunit" ] );
// Start the web server in a watch pre-task
// https://github.com/gruntjs/grunt-contrib-watch/issues/50
grunt.renameTask( "watch", "watch-repeatable" );
grunt.registerTask( "watch", [ "connect:livereload", "watch-repeatable" ] );
};