-
Notifications
You must be signed in to change notification settings - Fork 42
/
Gruntfile.js
186 lines (174 loc) · 5.04 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
// jscs:disable maximumLineLength
const fs = require('fs');
const path = require('path');
module.exports = function (grunt) {
// autoload installed tasks
[
'grunt-atomizer',
'grunt-contrib-clean',
'grunt-contrib-connect',
'grunt-contrib-watch',
'grunt-webpack'
].forEach((packageName) => {
let moduleTasks = path.resolve(__dirname, '..', 'node_modules', packageName, 'tasks');
if (!fs.existsSync(moduleTasks)) {
moduleTasks = path.resolve(process.cwd(), 'node_modules', packageName, 'tasks');
}
if (fs.existsSync(moduleTasks)) {
grunt.loadTasks(moduleTasks);
} else {
grunt.log.error(`${moduleTasks} could not be found.`);
}
});
// configurable paths
const { env } = process;
const projectConfig = {
src: 'src',
functional: 'tests/functional',
spec: 'tests/spec',
test_results_dir: grunt.option('test_results_dir') || 'artifacts'
};
grunt.initConfig({
project: projectConfig,
clean: {
functional: {
files: [
{
dot: true,
src: [
'<%= project.functional %>/main.js',
'<%= project.functional %>/css/atomic.css',
'<%= project.functional %>/console.js',
'<%= project.functional %>/*-functional.js'
]
}
]
}
},
// atomizer
atomizer: {
// used by functional tests
functional: {
files: [
{
src: ['<%= project.src %>/*.jsx', 'tests/**/*.jsx'],
dest: 'tests/functional/css/atomic.css'
}
]
}
},
// webpack
// create js rollup with webpack module loader for functional tests
webpack: {
functional: {
mode: 'development',
entry: {
main: './<%= project.functional %>/bootstrap.js'
},
output: {
path: path.resolve(process.cwd(), projectConfig.functional)
},
module: {
rules: [
{ test: /\.css$/, loader: 'style!css' },
{ test: /\.jsx$/, loader: 'jsx-loader' },
{ test: /\.json$/, loader: 'json-loader' }
]
}
}
},
// connect
// setup server for functional tests
connect: {
functional: {
options: {
port: 9999,
base: ['<%= project.functional %>', '.']
}
},
functionalOpen: {
options: {
port: 9999,
base: ['<%= project.functional %>', '.'],
open: {
target: 'http://127.0.0.1:9999/tests/functional/page.html'
}
}
}
},
watch: {
functional: {
files: ['<%= project.src%>/*.jsx', '<%= project.functional%>/*.jsx', '<%= project.functional%>/*.html'],
tasks: ['functional-debug']
}
},
'saucelabs-mocha': {
all: {
options: {
// this is apply for open source project https://saucelabs.com/open-source
username: process.env.SAUCE_USERNAME,
key: () => process.env.SAUCE_ACCESS_KEY,
testname: 'react-i13n func test',
urls: ['http://127.0.0.1:9999/tests/functional/page.html'],
build: process.env.TRAVIS_BUILD_NUMBER,
sauceConfig: {
'record-video': true,
'capture-html': false,
'record-screenshots': false
},
throttled: 3,
browsers: [
// {
// browserName: 'edge',
// platform: 'Windows 10',
// version: '16.16299'
// },
// {
// browserName: 'internet explorer',
// platform: 'Windows 10',
// version: '11.285'
// },
{
browserName: 'chrome',
platform: 'Windows 10',
version: '73'
},
{
browserName: 'firefox',
platform: 'Windows 7',
version: '66'
}
// {
// browserName: 'safari',
// platform: 'macOS 10.14',
// version: '12.0'
// }
]
}
}
}
});
grunt.loadNpmTasks('grunt-saucelabs');
// register custom tasks
// functional
// 2. run atomizer functional
// 3. copy files to tests/functional/
// 4. use webpack to create a js bundle to tests/functional/
// 5. get local ip address and available port then store in grunt config
// 6. set up local server to run functional tests
// 7. run protractor
grunt.registerTask('functional', [
'atomizer:functional',
'webpack:functional',
'connect:functional',
'saucelabs-mocha',
'clean:functional'
]);
// similar to functional, but don't run protractor, just open the test page
grunt.registerTask('functional-debug', [
'atomizer:functional',
'webpack:functional',
'connect:functionalOpen',
'watch:functional'
]);
};