Skip to content

Commit d1a26f0

Browse files
author
Nick Frasser
authored
Automated browser test fixes (#224)
* Automated test and browser matrix fixes Now tests against multiple jQuery and React versions * Continue using NPM instead of Yarn * Ensure vendor tasks finishes before starting karma * Additional text fixes and node compatibility * Improved gulp task scheduling * Test fixes for latest react version * Better Travis React installation * Improved polyfill serving on non-IE8 * Fix code coverage reporting * Fix mocha test dependency
1 parent 286ab32 commit d1a26f0

35 files changed

+10169
-5886
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ end_of_line = lf
1010
charset = utf-8
1111
trim_trailing_whitespace = true
1212
insert_final_newline = true
13+
14+
[*.yml]
15+
indent_style = space
16+
tab_width = 2

.eslintrc

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
{
2-
"parserOptions": {
3-
"ecmaVersion": 6,
4-
"sourceType": "module"
5-
},
6-
"env": {
7-
"browser": true,
8-
"node": true,
9-
"jquery": true,
10-
"es6": true
11-
},
12-
"rules": {
13-
"curly": 2,
14-
"eqeqeq": 2,
15-
"indent": [2, "tab"],
16-
"no-eq-null": 2,
17-
"quotes": [2, "single", "avoid-escape"],
18-
"semi": 2
19-
},
20-
"globals": {
21-
"__base": false,
22-
"__TLDS__": false,
23-
"after": false,
24-
"afterEach": false,
25-
"before": false,
26-
"beforeEach": false,
27-
"expect": false,
28-
"describe": false,
29-
"it": false
30-
}
2+
"extends": [
3+
"eslint:recommended"
4+
],
5+
"parserOptions": {
6+
"ecmaVersion": 6,
7+
"sourceType": "module"
8+
},
9+
"env": {
10+
"browser": true,
11+
"node": true,
12+
"jquery": true,
13+
"es6": true,
14+
"amd": true
15+
},
16+
"rules": {
17+
"curly": 2,
18+
"eqeqeq": 2,
19+
"no-eq-null": 2,
20+
"quotes": [2, "single", "avoid-escape"],
21+
"semi": 2
22+
},
23+
"globals": {
24+
"__base": false,
25+
"__TLDS__": false,
26+
"after": false,
27+
"afterEach": false,
28+
"before": false,
29+
"beforeEach": false,
30+
"expect": false,
31+
"describe": false,
32+
"it": false
33+
}
3134
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ lib-cov
2222

2323
# Coverage directory used by tools like istanbul
2424
coverage
25+
.nyc_output
2526

2627
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2728
.grunt
@@ -41,6 +42,7 @@ build
4142
!test/qunit/build
4243
dist
4344
lib
45+
vendor
4446

4547
# Specific to plugin website branch
4648
.sass-cache

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ js
1212
src
1313
templates
1414
test
15+
vendor
1516

1617
# Files
1718
.editorconfig

.travis.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "8.6"
5-
- "6.11"
6-
- "4.4"
4+
- "9.4"
5+
- "8.9"
6+
- "6.13"
77
env:
88
global:
99
- secure: LhH+mMqOktTe6cIt97PGKBfgUjZM8vRd0qddyg61FSxg7a3WrHQoHE8WdRioJ9+DDzpu/NSTsHEUFUpGN+kSRw1UY4tsNLH6HoBQnqrNN4tVOeefudJpdeteOKZrJ8r8TaA/eO7sAgXO2T+RLJ8+qTbhx8FVZtLaCAgkrS0w9Qk=
1010
- secure: Okwm1aAR3oo09AhHDsjFSq1UGlIUtWYYvYeoolJScC/UVFGMiK9oC4fzRtUHv3kXcnshDlcVDrr/Q5JL9Qx6E+tosPJp+tioaqE8X4IDbVk7PPs/ToOOEmWnGvxkgmfCGSDuneG8RVhILkhls3fbm0z+rRWlvJkjefeA96T6zps=
11+
matrix:
12+
- REACT_VERSION=0.14.0 JQUERY_VERSION=1.11.0
13+
- REACT_VERSION=16.0.0 JQUERY_VERSION=3.0.0
14+
15+
cache:
16+
directories:
17+
- node_modules
18+
1119
install:
1220
- npm install
13-
- npm install "jquery@1"
14-
- npm install "react@16"
21+
before_script:
22+
- 'if [ "$JQUERY_VERSION" ]; then npm install --force jquery@~$JQUERY_VERSION; fi'
23+
- 'if [ "$REACT_VERSION" ]; then npm install --force react-dom@~$REACT_VERSION react@~$REACT_VERSION; fi'
1524
script: ./run-tests.sh
16-
after_script: npm run coverage
25+
after_success: npm run coverage

gulpfile.js

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
'use strict';
1+
/* istanbul ignore file */
22

33
const gulp = require('gulp');
4-
const amdOptimize = require('amd-optimize');
54
const glob = require('glob');
65
const Server = require('karma').Server;
76
const merge = require('merge-stream');
@@ -13,7 +12,6 @@ const tlds = require('./tlds');
1312
const babel = require('gulp-babel');
1413
const clean = require('gulp-clean');
1514
const concat = require('gulp-concat');
16-
const istanbul = require('gulp-istanbul');
1715
const eslint = require('gulp-eslint');
1816
const mocha = require('gulp-mocha');
1917
const rename = require('gulp-rename');
@@ -51,7 +49,7 @@ var tldsReplaceStr = `'${tlds.join('|')}'.split('|')`;
5149
ES6 ~> babel (with CJS Node Modules)
5250
This populates the `lib` folder, allows usage with Node.js
5351
*/
54-
gulp.task('babel', () =>
52+
gulp.task('lib', () =>
5553
gulp.src(paths.src)
5654
.pipe(replace('__TLDS__', tldsReplaceStr))
5755
.pipe(babel())
@@ -61,7 +59,7 @@ gulp.task('babel', () =>
6159
/**
6260
ES6 to babel AMD modules
6361
*/
64-
gulp.task('babel-amd-core', () =>
62+
gulp.task('amd', () =>
6563
gulp.src(paths.src)
6664
.pipe(replace('__TLDS__', tldsReplaceStr))
6765
.pipe(babel({
@@ -76,51 +74,50 @@ gulp.task('babel-amd-core', () =>
7674
.pipe(gulp.dest('build/amd')) // Required for building plugins separately
7775
);
7876

79-
8077
/**
81-
ES6 to babel AMD modules
82-
Must run interfaces first because a more optimized core linkify payload will
83-
overwrite the AMD-generated one
78+
Build core linkify.js
8479
*/
85-
gulp.task('babel-amd', ['babel-amd-core'], () =>
86-
gulp.src(paths.srcCore)
80+
gulp.task('build-core', () =>
81+
gulp.src(paths.srcCore, {read: false})
8782
.pipe(rollup({
8883
bundle: {
89-
format: 'amd',
90-
moduleId: 'linkify',
84+
format: 'iife',
9185
moduleName: 'linkify'
9286
}
9387
}))
9488
.pipe(babel())
9589
.pipe(replace('__TLDS__', tldsReplaceStr))
96-
.pipe(quickEs3())
97-
.pipe(concat('linkify.amd.js'))
90+
.pipe(replace('undefined.', 'self.'))
91+
.pipe(wrap({src: 'templates/linkify.js'}))
9892
.pipe(gulp.dest('build'))
9993
);
10094

10195
/**
102-
Build core linkify.js
96+
ES6 to babel AMD modules
97+
Must run interfaces first because a more optimized core linkify payload will
98+
overwrite the AMD-generated one
10399
*/
104-
gulp.task('build-core', () =>
105-
gulp.src(paths.srcCore, {read: false})
100+
gulp.task('build-amd-core', () =>
101+
gulp.src(paths.srcCore)
106102
.pipe(rollup({
107103
bundle: {
108-
format: 'iife',
104+
format: 'amd',
105+
moduleId: 'linkify',
109106
moduleName: 'linkify'
110107
}
111108
}))
112109
.pipe(babel())
113110
.pipe(replace('__TLDS__', tldsReplaceStr))
114-
.pipe(replace('undefined.', 'self.'))
115-
.pipe(wrap({src: 'templates/linkify.js'}))
111+
.pipe(quickEs3())
112+
.pipe(concat('linkify.amd.js'))
116113
.pipe(gulp.dest('build'))
117114
);
118115

119116
/**
120117
Build root linkify interfaces (files located at the root src folder other
121118
than linkify.js).
122119
*/
123-
gulp.task('build-interfaces', () => {
120+
gulp.task('build-interfaces', ['amd'], () => {
124121

125122
// Core linkify functionality as plugins
126123
let interfaces = [
@@ -195,7 +192,7 @@ gulp.task('build-interfaces', () => {
195192
});
196193

197194

198-
gulp.task('build-plugins', () => {
195+
gulp.task('build-plugins', ['amd'], () => {
199196

200197
let streams = [];
201198

@@ -250,14 +247,26 @@ gulp.task('build-polyfill', () =>
250247

251248
// Build steps
252249
gulp.task('build', [
253-
'babel',
254-
'babel-amd-core',
255-
'babel-amd',
250+
'lib',
256251
'build-core',
252+
'build-amd-core',
257253
'build-interfaces',
258254
'build-plugins',
259255
'build-polyfill'
260-
], (cb) => { cb(); });
256+
]);
257+
258+
// Copy React into vendor directory for use in tests
259+
// This is required because React's location may vary between versions
260+
gulp.task('vendor', () =>
261+
gulp.src([
262+
'node_modules/react/dist/react.min.js',
263+
'node_modules/react-dom/dist/react-dom.min.js',
264+
'node_modules/react/umd/react.production.min.js',
265+
'node_modules/react-dom/umd/react-dom.production.min.js'
266+
])
267+
.pipe(rename(path => path.basename = path.basename.replace(/\.production/, '')))
268+
.pipe(gulp.dest('vendor'))
269+
);
261270

262271
/**
263272
Lint using eslint
@@ -279,80 +288,63 @@ gulp.task('eslint', () =>
279288
/**
280289
Run mocha tests
281290
*/
282-
gulp.task('mocha', ['eslint', 'build'], () =>
283-
gulp.src(paths.test, {read: false})
284-
.pipe(mocha())
291+
gulp.task('mocha', ['build'], () =>
292+
gulp.src(paths.test).pipe(mocha())
285293
);
286294

287-
/**
288-
Code coverage reort for mocha tests
289-
*/
290-
gulp.task('coverage', ['eslint', 'dist'], (callback) => {
291-
// IMPORTANT: return not required here (and will actually cause bugs!)
292-
gulp.src(paths.libTest)
293-
.pipe(istanbul()) // Covering files
294-
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
295-
.on('finish', () => {
296-
gulp.src(paths.test, {read: false})
297-
.pipe(mocha())
298-
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
299-
.on('end', callback);
300-
});
301-
});
302-
303-
gulp.task('karma', (callback) => {
295+
gulp.task('karma', ['vendor'], (callback) => {
304296
let server = new Server({
305297
configFile: __dirname + '/test/dev.conf.js',
306298
singleRun: true
307299
}, callback);
308300
return server.start();
309301
});
310302

311-
gulp.task('karma-chrome', (callback) => {
303+
gulp.task('karma-chrome', ['vendor'], (callback) => {
312304
let server = new Server({
313305
configFile: __dirname + '/test/chrome.conf.js',
314306
}, callback);
315307
return server.start();
316308
});
317309

318-
gulp.task('karma-firefox', (callback) => {
310+
gulp.task('karma-firefox', ['vendor'], (callback) => {
319311
let server = new Server({
320312
configFile: __dirname + '/test/firefox.conf.js',
321313
}, callback);
322314
return server.start();
323315
});
324316

325-
gulp.task('karma-ci', (callback) => {
317+
gulp.task('karma-ci', ['vendor'], (callback) => {
326318
let server = new Server({
327319
configFile: __dirname + '/test/ci.conf.js',
328320
singleRun: true
329321
}, callback);
330322
return server.start();
331323
});
332324

333-
gulp.task('karma-amd', (callback) => {
325+
gulp.task('karma-amd', ['vendor'], (callback) => {
334326
let server = new Server({
335327
configFile: __dirname + '/test/dev.amd.conf.js',
336328
singleRun: true
337329
}, callback);
338330
return server.start();
339331
});
340332

341-
gulp.task('karma-amd-chrome', (callback) => {
333+
gulp.task('karma-amd-chrome', ['vendor'], (callback) => {
342334
let server = new Server({
343335
configFile: __dirname + '/test/chrome.amd.conf.js',
344336
}, callback);
345337
return server.start();
346338
});
347339

348-
gulp.task('karma-amd-firefox', (callback) => {
340+
gulp.task('karma-amd-firefox', ['vendor'], (callback) => {
349341
let server = new Server({
350342
configFile: __dirname + '/test/firefox.amd.conf.js',
351343
}, callback);
352344
return server.start();
353345
});
354346

355-
gulp.task('karma-amd-ci', (callback) => {
347+
gulp.task('karma-amd-ci', ['vendor'], (callback) => {
356348
let server = new Server({
357349
configFile: __dirname + '/test/ci.amd.conf.js',
358350
singleRun: true
@@ -386,10 +378,10 @@ gulp.task('uglify', ['build'], () => {
386378

387379
gulp.task('dist', ['uglify']);
388380
gulp.task('test', (callback) =>
389-
runSequence('coverage', 'karma', 'karma-amd', callback)
381+
runSequence('eslint', 'mocha', 'dist', 'karma', 'karma-amd', callback)
390382
);
391383
gulp.task('test-ci', (callback) =>
392-
runSequence('karma-ci', 'karma-amd-ci', callback)
384+
runSequence('dist', 'karma-ci', 'karma-amd-ci', callback)
393385
);
394386

395387
gulp.task('clean', () =>
@@ -400,12 +392,13 @@ gulp.task('clean', () =>
400392
'dist',
401393
'js',
402394
'lib',
395+
'vendor'
403396
], {read: false}).pipe(clean())
404397
);
405398

406399
/**
407400
Build JS and begin watching for changes
408401
*/
409-
gulp.task('default', ['eslint', 'babel'], () =>
410-
gulp.watch(paths.src, ['eslint', 'babel'])
402+
gulp.task('default', ['eslint', 'lib'], () =>
403+
gulp.watch(paths.src, ['eslint', 'lib'])
411404
);

0 commit comments

Comments
 (0)