From 4c9affff8ce47f17c5e8eb4f93a1a28b5f6dfda8 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 13 Mar 2019 11:48:34 -0500 Subject: [PATCH 1/4] chore: test axe examples in ci --- .circleci/config.yml | 11 ++++ appveyor.yml | 20 ++++++++ .../chrome-debugging-protocol/package.json | 7 ++- doc/examples/jasmine/Gruntfile.js | 16 ------ doc/examples/jasmine/karma.conf.js | 51 +++++++++++++++++++ doc/examples/jasmine/package.json | 9 ++-- doc/examples/jest_react/link.test.js | 2 +- doc/examples/jest_react/package.json | 2 +- doc/examples/mocha/package.json | 2 +- doc/examples/phantomjs/axe-phantom.js | 2 +- doc/examples/phantomjs/package.json | 6 +-- doc/examples/puppeteer/package.json | 5 +- doc/examples/qunit/package.json | 2 +- doc/examples/test-examples.js | 36 +++++++++++++ package.json | 3 +- 15 files changed, 142 insertions(+), 32 deletions(-) create mode 100644 appveyor.yml delete mode 100644 doc/examples/jasmine/Gruntfile.js create mode 100644 doc/examples/jasmine/karma.conf.js create mode 100644 doc/examples/test-examples.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 89f251332e..782b15ecb0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,6 +57,13 @@ jobs: - phantomjs - run: npm run test + # Run examples under `doc/examples` + test_examples: + <<: *defaults + steps: + - checkout + - run: npm run test:examples + # Release a "next" version next_release: <<: *defaults @@ -92,11 +99,13 @@ workflows: requires: - dependencies - lint + - test_examples # Hold for approval - hold: type: approval requires: - test + - test_examples filters: # We only want to hold on these two branches, as PR review acts as approval for PRs branches: @@ -108,6 +117,7 @@ workflows: requires: - dependencies - test + - test_examples - hold filters: branches: @@ -117,6 +127,7 @@ workflows: requires: - dependencies - test + - test_examples - hold filters: branches: diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000..40d8a911fe --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,20 @@ +version: 1.0.{build}-{branch} + +# Test against this version of node. +environment: + nodejs_version: "10" +skip_tags: true + +# Install scripts. (runs after repo cloning) +install: + - ps: Install-Product node $env:nodejs_version + - npm install + +# Post-install test scripts. +test_script: + - node --version + - npm --version + - npm run test:examples + +# Don't actually build. +build: off \ No newline at end of file diff --git a/doc/examples/chrome-debugging-protocol/package.json b/doc/examples/chrome-debugging-protocol/package.json index 95f5b2b25e..7d2080bcc9 100644 --- a/doc/examples/chrome-debugging-protocol/package.json +++ b/doc/examples/chrome-debugging-protocol/package.json @@ -1,8 +1,11 @@ { "name": "axe-cdp", "private": true, + "scripts": { + "test": "echo 'No test specified.'" + }, "dependencies": { - "axe-core": "^3.1.1", - "chrome-remote-interface": "^0.26.0" + "axe-core": "^3.2.2", + "chrome-remote-interface": "^0.27.1" } } diff --git a/doc/examples/jasmine/Gruntfile.js b/doc/examples/jasmine/Gruntfile.js deleted file mode 100644 index 6871ee18e9..0000000000 --- a/doc/examples/jasmine/Gruntfile.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(grunt) { - 'use strict'; - - grunt.loadNpmTasks('grunt-contrib-jasmine'); - - grunt.initConfig({ - jasmine: { - test: { - src: ['node_modules/axe-core/axe.js'], - options: { - specs: 'spec/**/*.js' - } - } - } - }); -}; diff --git a/doc/examples/jasmine/karma.conf.js b/doc/examples/jasmine/karma.conf.js new file mode 100644 index 0000000000..48df44fd65 --- /dev/null +++ b/doc/examples/jasmine/karma.conf.js @@ -0,0 +1,51 @@ +// Karma configuration +module.exports = function(config) { + config.set({ + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + // list of files / patterns to load in the browser + files: ['spec/**/*.js', 'node_modules/axe-core/axe.js'], + + // list of files / patterns to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: {}, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['ChromeHeadless'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }); +}; diff --git a/doc/examples/jasmine/package.json b/doc/examples/jasmine/package.json index 5b74fa8ea8..84074ba228 100644 --- a/doc/examples/jasmine/package.json +++ b/doc/examples/jasmine/package.json @@ -10,11 +10,12 @@ }, "dependencies": {}, "scripts": { - "test": "grunt jasmine" + "test": "karma start karma.conf.js" }, "devDependencies": { - "axe-core": "^3.1.1", - "grunt": "~1.0.2", - "grunt-contrib-jasmine": "~2.0.0" + "axe-core": "^3.2.2", + "karma": "^4.0.1", + "karma-chrome-launcher": "^2.2.0", + "karma-jasmine": "^2.0.1" } } diff --git a/doc/examples/jest_react/link.test.js b/doc/examples/jest_react/link.test.js index 2d67b64f35..d2708fb35b 100644 --- a/doc/examples/jest_react/link.test.js +++ b/doc/examples/jest_react/link.test.js @@ -2,7 +2,7 @@ import React from 'react'; import axe from 'axe-core'; import { mountToDoc } from './test-helpers'; -import Link from './Link'; +import Link from './link'; test('Link has no aXe violations', done => { const linkComponent = mountToDoc( diff --git a/doc/examples/jest_react/package.json b/doc/examples/jest_react/package.json index 14f669842d..ba6a23d62e 100644 --- a/doc/examples/jest_react/package.json +++ b/doc/examples/jest_react/package.json @@ -13,7 +13,7 @@ "test": "jest" }, "devDependencies": { - "axe-core": "^3.1.1", + "axe-core": "^3.2.2", "babel-jest": "^23.0.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", diff --git a/doc/examples/mocha/package.json b/doc/examples/mocha/package.json index 8096f7eb1d..d17a094200 100644 --- a/doc/examples/mocha/package.json +++ b/doc/examples/mocha/package.json @@ -13,7 +13,7 @@ "test": "grunt mocha" }, "devDependencies": { - "axe-core": "^3.1.1", + "axe-core": "^3.2.2", "chai": "~4.1.2", "grunt": "~1.0.2", "grunt-mocha": "1.2.0" diff --git a/doc/examples/phantomjs/axe-phantom.js b/doc/examples/phantomjs/axe-phantom.js index d873d4d33c..7039ec8e18 100644 --- a/doc/examples/phantomjs/axe-phantom.js +++ b/doc/examples/phantomjs/axe-phantom.js @@ -27,7 +27,7 @@ page.open(args[1], function(status) { page.switchToMainFrame(); page.evaluateAsync(function() { /*global axe */ - axe.run(function(err, results) { + axe.run({ include: ['#page'] }, function(err, results) { if (err) { throw err; } diff --git a/doc/examples/phantomjs/package.json b/doc/examples/phantomjs/package.json index ee967c1902..2826466c9a 100644 --- a/doc/examples/phantomjs/package.json +++ b/doc/examples/phantomjs/package.json @@ -1,6 +1,6 @@ { "name": "axe-phantomjs-example", - "description": "aXe Mocha Example", + "description": "aXe PhantomJS Example", "version": "0.0.1", "private": true, "author": { @@ -10,10 +10,10 @@ }, "dependencies": {}, "scripts": { - "test": "phantomjs axe-phantom.js http://www.deque.com" + "test": "phantomjs axe-phantom.js https://www.deque.com" }, "devDependencies": { - "axe-core": "^3.1.1", + "axe-core": "^3.2.2", "phantomjs": "^2.1.7" } } diff --git a/doc/examples/puppeteer/package.json b/doc/examples/puppeteer/package.json index ae316c6414..a0bf27a863 100644 --- a/doc/examples/puppeteer/package.json +++ b/doc/examples/puppeteer/package.json @@ -3,8 +3,11 @@ "version": "0.0.0", "private": true, "main": "axe-puppeteer.js", + "scripts": { + "test": "node axe-puppeteer.js https://deque.com" + }, "dependencies": { - "axe-core": "^3.1.1", + "axe-core": "^3.2.2", "puppeteer": "^1.6.0" } } diff --git a/doc/examples/qunit/package.json b/doc/examples/qunit/package.json index c067db2ae2..e0732e42de 100644 --- a/doc/examples/qunit/package.json +++ b/doc/examples/qunit/package.json @@ -13,7 +13,7 @@ "test": "grunt qunit" }, "devDependencies": { - "axe-core": "^3.1.1", + "axe-core": "^3.2.2", "grunt": "~1.0.2", "grunt-contrib-qunit": "~3.1.0", "qunitjs": "~2.4.1" diff --git a/doc/examples/test-examples.js b/doc/examples/test-examples.js new file mode 100644 index 0000000000..fbc5fb318b --- /dev/null +++ b/doc/examples/test-examples.js @@ -0,0 +1,36 @@ +const { readdirSync, statSync } = require('fs'); +const { join } = require('path'); +const { spawn } = require('child_process'); +const exampleDirs = readdirSync(__dirname) + .map(dir => join(__dirname, dir)) + .filter(dir => statSync(dir).isDirectory()); + +async function runner(dir) { + let child = spawn('npm install && npm test', { + cwd: dir, + shell: true, + stdio: 'inherit' + }); + + return new Promise((resolve, reject) => { + child.on('close', code => { + if (code === 0) { + resolve(); + } else { + reject(); + } + }); + }); +} + +(async () => { + await Promise.all(exampleDirs.map(runner)) + .then(() => { + // Return successful exit + process.exit(); + }) + .catch(err => { + console.log(err); + process.exit(1); + }); +})(); diff --git a/package.json b/package.json index a77e7d1b80..1f7072507f 100644 --- a/package.json +++ b/package.json @@ -62,9 +62,10 @@ "build": "grunt", "eslint": "eslint --color --format stylish '{lib,test,build,doc}/**/*.js' 'Gruntfile.js'", "test": "npm run retire && tsc && grunt test", + "test:examples": "node ./doc/examples/test-examples", "version": "echo \"use 'npm run release' to bump axe-core version\" && exit 1", "prepublishOnly": "grunt build && grunt file-exists", - "retire": "retire --jspath 'lib' --nodepath './' --ignorefile '.retireignore.json' --severity 'medium'", + "retire": "retire --jspath lib --nodepath ./ --ignorefile .retireignore.json --severity medium", "release": "standard-version -a", "rule-gen": "node build/rule-generator", "next-release": "standard-version --scripts.prebump=./build/next-version.js --skip.commit=true --skip.tag=true", From 461ce8308e410035cfec08b629f76ff0adb76024 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 18 Mar 2019 11:32:33 -0500 Subject: [PATCH 2/4] fix: use execa instead of child_process.spawn --- .circleci/config.yml | 5 ++++- doc/examples/test-examples.js | 40 ++++++++++++----------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 782b15ecb0..e71b3ab5f2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,6 +62,7 @@ jobs: <<: *defaults steps: - checkout + - <<: *restore_dependency_cache - run: npm run test:examples # Release a "next" version @@ -99,7 +100,9 @@ workflows: requires: - dependencies - lint - - test_examples + - test_examples: + requires: + - test # Hold for approval - hold: type: approval diff --git a/doc/examples/test-examples.js b/doc/examples/test-examples.js index fbc5fb318b..6d41a2323e 100644 --- a/doc/examples/test-examples.js +++ b/doc/examples/test-examples.js @@ -1,36 +1,22 @@ const { readdirSync, statSync } = require('fs'); const { join } = require('path'); -const { spawn } = require('child_process'); +const execa = require('execa'); const exampleDirs = readdirSync(__dirname) .map(dir => join(__dirname, dir)) .filter(dir => statSync(dir).isDirectory()); async function runner(dir) { - let child = spawn('npm install && npm test', { - cwd: dir, - shell: true, - stdio: 'inherit' - }); - - return new Promise((resolve, reject) => { - child.on('close', code => { - if (code === 0) { - resolve(); - } else { - reject(); - } - }); - }); + const config = { cwd: dir, stdio: 'inherit' }; + await execa.shell('npm install', config); + return execa.shell('npm test', config); } -(async () => { - await Promise.all(exampleDirs.map(runner)) - .then(() => { - // Return successful exit - process.exit(); - }) - .catch(err => { - console.log(err); - process.exit(1); - }); -})(); +Promise.all(exampleDirs.map(runner)) + .then(() => { + // Return successful exit + process.exit(); + }) + .catch(err => { + console.error(err); + process.exit(1); + }); From 6ed71c91e299374f760bf308641208876c656447 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 18 Mar 2019 11:33:31 -0500 Subject: [PATCH 3/4] fix: remove unnecessary comments --- doc/examples/jasmine/karma.conf.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/doc/examples/jasmine/karma.conf.js b/doc/examples/jasmine/karma.conf.js index 48df44fd65..e8cf2f0630 100644 --- a/doc/examples/jasmine/karma.conf.js +++ b/doc/examples/jasmine/karma.conf.js @@ -1,51 +1,29 @@ -// Karma configuration module.exports = function(config) { config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine'], - // list of files / patterns to load in the browser files: ['spec/**/*.js', 'node_modules/axe-core/axe.js'], - // list of files / patterns to exclude exclude: [], - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: {}, - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress'], - // web server port port: 9876, - // enable / disable colors in the output (reporters and logs) colors: true, - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_INFO, - // enable / disable watching file and executing tests whenever any file changes autoWatch: true, - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['ChromeHeadless'], - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits singleRun: true, - // Concurrency level - // how many browser should be started simultaneous concurrency: Infinity }); }; From e5751039eaee3889cab0a00460d845e65db2f0fc Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 18 Mar 2019 11:39:35 -0500 Subject: [PATCH 4/4] ci: remove appveyor config --- appveyor.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 40d8a911fe..0000000000 --- a/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: 1.0.{build}-{branch} - -# Test against this version of node. -environment: - nodejs_version: "10" -skip_tags: true - -# Install scripts. (runs after repo cloning) -install: - - ps: Install-Product node $env:nodejs_version - - npm install - -# Post-install test scripts. -test_script: - - node --version - - npm --version - - npm run test:examples - -# Don't actually build. -build: off \ No newline at end of file