Skip to content

Commit

Permalink
Add test framework (chartjs#287)
Browse files Browse the repository at this point in the history
* Add test framework
  • Loading branch information
kurkle authored Dec 27, 2020
1 parent 323ac14 commit ce1b722
Show file tree
Hide file tree
Showing 11 changed files with 2,301 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

extends:
- chartjs
- plugin:es/no-2019
- plugin:es/no-new-in-es2019

env:
es6: true
Expand Down
24 changes: 16 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

outputs:
coveralls: ${{ steps.changes.outputs.src }}

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
os: [ubuntu-latest, windows-latest]
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: |
npm ci
npm run build
if [ "${{ runner.os }}" == "Windows" ]; then
npm test
else
xvfb-run --auto-servernum npm test
fi
shell: bash
106 changes: 106 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const istanbul = require('rollup-plugin-istanbul');
const resolve = require('@rollup/plugin-node-resolve').default;
const builds = require('./rollup.config');
const yargs = require('yargs');

module.exports = function(karma) {
const args = yargs
.option('verbose', {default: false})
.argv;

const grep = args.grep === true ? '' : args.grep;
const specPattern = 'test/specs/**/*' + grep + '*.js';

// Use the same rollup config as our dist files: when debugging (npm run dev),
// we will prefer the unminified build which is easier to browse and works
// better with source mapping. In other cases, pick the minified build to
// make sure that the minification process (terser) doesn't break anything.
const regex = karma.autoWatch ? /chartjs-plugin-annotation\.js$/ : /chartjs-plugin-annotation\.min\.js$/;
const build = builds.filter(v => v.output.file && v.output.file.match(regex))[0];

if (args.coverage) {
build.plugins = [
resolve(),
istanbul({exclude: ['node_modules/**/*.js', 'package.json']})
];
}

karma.set({
frameworks: ['jasmine'],
reporters: ['progress', 'kjhtml'],
browsers: (args.browsers || 'chrome,firefox').split(','),
logLevel: karma.LOG_INFO,

client: {
jasmine: {
failFast: !!karma.autoWatch
}
},

// Explicitly disable hardware acceleration to make image
// diff more stable when ran on Travis and dev machine.
// https://github.com/chartjs/Chart.js/pull/5629
customLaunchers: {
chrome: {
base: 'Chrome',
flags: [
'--disable-accelerated-2d-canvas'
]
},
firefox: {
base: 'Firefox',
prefs: {
'layers.acceleration.disabled': true
}
}
},

files: [
{pattern: 'test/fixtures/**/*.js', included: false},
{pattern: 'test/fixtures/**/*.png', included: false},
{pattern: 'node_modules/chart.js/dist/chart.js'},
{pattern: 'src/index.js', watched: false},
{pattern: 'test/index.js'},
{pattern: specPattern}
],

preprocessors: {
'src/index.js': ['sources'],
'test/index.js': ['rollup']
},

rollupPreprocessor: {
plugins: [
resolve(),
],
output: {
name: 'test',
format: 'umd',
sourcemap: karma.autoWatch ? 'inline' : false
}
},

customPreprocessors: {
sources: {
base: 'rollup',
options: build
}
},

// These settings deal with browser disconnects. We had seen test flakiness from Firefox
// [Firefox 56.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
// https://github.com/jasmine/jasmine/issues/1327#issuecomment-332939551
browserDisconnectTolerance: 3
});

if (args.coverage) {
karma.reporters.push('coverage');
karma.coverageReporter = {
dir: 'coverage/',
reporters: [
{type: 'html', subdir: 'html'},
{type: 'lcovonly', subdir: (browser) => browser.toLowerCase().split(/[ /-]/)[0]}
]
};
}
};
Loading

0 comments on commit ce1b722

Please sign in to comment.