Skip to content

Commit b50b84d

Browse files
committed
Set up travis to build and run tests.
1 parent b4133b2 commit b50b84d

File tree

9 files changed

+1447
-21
lines changed

9 files changed

+1447
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# production
1212
/build
13+
/dist
1314

1415
# Webstorm IDE
1516
/.idea

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
language: node_js
22
node_js:
33
- "14"
4+
addons:
5+
firefox: latest
6+
chrome: stable
7+
dist: xenial
8+
services:
9+
- xvfb
10+
os:
11+
- linux
12+
- osx
13+
script: yarn test

Gruntfile.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Copyright 2013 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module.exports = function(grunt) {
18+
const closurePackage = require('google-closure-compiler');
19+
closurePackage.grunt(grunt);
20+
21+
grunt.initConfig({
22+
'pkg': grunt.file.readJSON('package.json'),
23+
24+
// Using https://www.npmjs.com/package/google-closure-compiler
25+
'closure-compiler': {
26+
my_target: {
27+
files: {
28+
'dist/measure.js': 'src/**/*.js',
29+
},
30+
options: {
31+
js: [
32+
'node_modules/google-closure-library/closure/goog/base.js'
33+
],
34+
hide_warnings_for: 'google-closure-library',
35+
compilation_level: 'ADVANCED_OPTIMIZATIONS',
36+
language_in: 'ECMASCRIPT6',
37+
output_wrapper: '(function(){%output%})();',
38+
jscomp_warning: 'lintChecks',
39+
},
40+
},
41+
},
42+
'karma': {
43+
options: {
44+
// Continue after running the tests
45+
singleRun: true,
46+
},
47+
unit: {
48+
configFile: 'karma.conf.js',
49+
},
50+
integration: {
51+
configFile: 'test/integration/karma.conf.js',
52+
},
53+
unitBrowsers: {
54+
options: {
55+
// Run tests on all the browsers on the system.
56+
frameworks: ['jasmine', 'detectBrowsers'],
57+
detectBrowsers: {
58+
enabled: true,
59+
// Don't try to load phantomJS, it may not exist.
60+
usePhantomJS: false,
61+
},
62+
// Travis needs it to run browsers.
63+
flags: ['--no-sandbox'],
64+
},
65+
configFile: 'karma.conf.js',
66+
},
67+
integrationBrowsers: {
68+
options: { // same as for unitBrowsers
69+
frameworks: ['jasmine', 'detectBrowsers'],
70+
detectBrowsers: {
71+
enabled: true,
72+
usePhantomJS: false,
73+
},
74+
flags: ['--no-sandbox'],
75+
},
76+
configFile: 'test/integration/karma.conf.js',
77+
},
78+
},
79+
});
80+
81+
grunt.loadNpmTasks('grunt-karma');
82+
83+
grunt.registerTask('default', [
84+
'closure-compiler',
85+
'karma:unit',
86+
'karma:integration',
87+
]);
88+
89+
grunt.registerTask('test', [
90+
'closure-compiler',
91+
'karma:unitBrowsers',
92+
'karma:integrationBrowsers',
93+
]);
94+
};

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ yarn global add karma-cli
3030
npm install -g karma-cli
3131
```
3232

33-
Next, run the tests with karma
33+
Next, run the unit tests with karma from the root directory
3434

3535
```shell script
3636
karma start
37-
```
37+
```
38+
39+
To run the integration tests instead of the unit tests,
40+
41+
```shell script
42+
karma start test/integration/karma.conf.js
43+
```

karma.conf.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,37 @@ module.exports = function(config) {
77
frameworks: ['jasmine'],
88
// automatically run tests for files matching these regex
99
files: [
10-
// test files
10+
// ----------------- Third Party Dependencies ----------------------------
11+
{pattern: 'node_modules/google-closure-library/closure/goog/base.js'},
12+
// ------------------------ Source Files ---------------------------------
13+
// Dependencies must be listed before the file they are used in for
14+
// the googmodule preprocessor to function properly.
15+
{pattern: 'src/**/*.js'},
16+
// ------------------------- Test Files ----------------------------------
1117
'test/*_test.js'
1218
],
19+
preprocessors: {'**/*.js': ['googmodule']},
1320
plugins: [
1421
require('karma-jasmine'),
22+
require('karma-detect-browsers'),
1523
require('karma-chrome-launcher'),
24+
require('karma-firefox-launcher'),
25+
require('karma-ie-launcher'),
26+
require('karma-safari-launcher'),
1627
require('karma-spec-reporter'),
17-
require('karma-jasmine-html-reporter')
28+
require('karma-jasmine-html-reporter'),
29+
require('karma-googmodule-preprocessor'),
1830
],
1931
reporters: ['spec', 'kjhtml'],
2032
colors: true,
2133
logLevel: config.LOG_DISABLE,
22-
// run tests when a file changes
34+
// Run tests when a file changes.
2335
autoWatch: true,
2436
browsers: ['Chrome'],
2537
client: {
2638
clearContext: false
2739
},
28-
// if you close the browser, it will not pop up again
40+
// If you close the browser, it will not pop up again.
2941
retryLimit: 0,
3042
})
3143
}

package.json

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
{
2+
"scripts": {
3+
"start": "grunt",
4+
"test": "grunt test"
5+
},
26
"dependencies": {
3-
"jasmine": "^3.5.0"
7+
"google-closure-compiler": "^20200628.0.0",
8+
"google-closure-library": "^20200628.0.0"
49
},
510
"devDependencies": {
11+
"grunt": "^1.2.1",
12+
"grunt-karma": "^4.0.0",
13+
14+
"jasmine": "^3.5.0",
615
"jasmine-core": "^3.5.0",
16+
717
"karma": "^5.1.0",
8-
"karma-chrome-launcher": "^3.1.0",
18+
"karma-googmodule-preprocessor": "^1.0.1",
919
"karma-jasmine": "^3.3.1",
1020
"karma-jasmine-html-reporter": "^1.5.4",
11-
"karma-spec-reporter": "^0.0.32"
12-
},
13-
"scripts": {
14-
"test": "karma start --single-run --browsers ChromeHeadless"
21+
"karma-spec-reporter": "^0.0.32",
22+
23+
"karma-detect-browsers": "^2.3.3",
24+
"karma-chrome-launcher": "^3.1.0",
25+
"karma-firefox-launcher": "^1.3.0",
26+
"karma-ie-launcher": "^1.0.0",
27+
"karma-safari-launcher": "^1.0.0"
1528
}
1629
}

test/integration/integration_test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* TODO: Replace this test file with real tests
3+
*/
4+
describe('Test that the integration tests are running', function(){
5+
it('should pass this test', function(){
6+
expect('this test').not.toBe('here later');
7+
});
8+
})

test/integration/karma.conf.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const baseConfig = require('../../karma.conf');
2+
3+
module.exports = function(config) {
4+
baseConfig(config);
5+
config.set({
6+
files: [
7+
'./**_test.js',
8+
'../../dist/measure.js',
9+
],
10+
});
11+
};

0 commit comments

Comments
 (0)