Skip to content

Commit

Permalink
chore(major): Ace 1.2 supersedes v1.1.1 (PR #314)
Browse files Browse the repository at this point in the history
Summary:
* Based on DAISY's own fork of Deque's Axe (latest v4 version), instead of patching Axe's distributed Javascript bundles (see daisy/axe-core#4 )
* Better localization tooling for Axe, integration of Axe translations
* Two Axe "runners": Puppeteer (default for Ace CLI), and Electron (can be used in CLI, and used by Ace App), Chromium web browser engine is used in both cases, but Electron runner uses a HTTP server to simulate a typical reading system environment. Unit tests plumbing for both platforms (Continuous Integration server only executes the Puppeteer ones, for faster builds). Runtime performance is near-identical (there is a developer script to check this).
* NodeJS >=10 requirement
* NPM package dependencies updated to latest versions (except where NodeJS requirement is higher). Added developer scripts to facilitate version checking and incremental updates at regular intervals (i.e. `package.json` exact references and `yarn.lock` maintenance)
* All Ace sub-packages (`@daisy/` organisation scope on NPM) have exact same semantic version (easier deployment with developer script that automates NPM publish)
* Fixes bugs that couldn't easily be fixed in Ace 1.1.1 (the last of v1), due to older Axe (v3 instead of v4) and due to older NPM package dependencies that were necessary for compatibility with legacy NodeJS requirement (now deprecated / deemed unsecure).
  • Loading branch information
danielweck authored Apr 8, 2021
1 parent 87947c9 commit e974684
Show file tree
Hide file tree
Showing 180 changed files with 13,929 additions and 4,886 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"targets": {
"node": [
"8"
"10"
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ website/site
.DS_Store
._*
Thumbs.db

.history
15 changes: 0 additions & 15 deletions .snyk

This file was deleted.

10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ language: node_js
node_js:
- node
- lts/*
- 8
- 10
#services: xvfb
addons:
apt:
packages:
- xvfb
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.2.1
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.22.4
- export PATH="$HOME/.yarn/bin:$PATH"
before_script:
- yarn patchJestForTravis
script:
# - yarn snyk test
- xvfb-run yarn test --runInBand
- xvfb-run yarn test-cli --runInBand
# - xvfb-run yarn test-electron --runInBand
# - xvfb-run yarn test-electron-cli --runInBand
branches:
only:
- master
Expand Down
7 changes: 7 additions & 0 deletions jest.config-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const common = require('./jest.config-common');
module.exports = {
...common,
testMatch: [
'<rootDir>/tests/__tests__/cli.test.js',
],
};
18 changes: 18 additions & 0 deletions jest.config-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
verbose: true,
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/tests/jest-setup.js'],
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/.history/',
'<rootDir>/website/',
'<rootDir>/scripts/',
'<rootDir>/resources/',
'<rootDir>/CompareAxeRunners/',
'<rootDir>/tests/data/',
],
testMatch: [
"<rootDir>/tests/__tests__/**/*.js",
"<rootDir>/packages/**/src/**/(*.)+test.js",
],
};
8 changes: 8 additions & 0 deletions jest.config-electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const common = require('./jest.config-common');
module.exports = {
...common,
runner: '@jest-runner/electron/main',
testPathIgnorePatterns: common.testPathIgnorePatterns.concat([
'<rootDir>/tests/__tests__/cli',
]),
};
7 changes: 7 additions & 0 deletions jest.config-puppeteer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const common = require('./jest.config-common');
module.exports = {
...common,
testPathIgnorePatterns: common.testPathIgnorePatterns.concat([
'<rootDir>/tests/__tests__/cli',
]),
};
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.5.1",
"version": "1.1.1",
"lerna": "4.0.0",
"version": "1.2.0-beta.15",
"npmClient": "yarn",
"useWorkspaces": true
}
77 changes: 44 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,65 @@
"workspaces": [
"packages/*"
],
"version": "1.2.0-beta.15",
"engines": {
"node": ">=10.0.0",
"yarn": "^1.22.5",
"npm": ">=6.14.12"
},
"devDependencies": {
"@daisy/jest-env-puppeteer": "^1.0.0",
"@daisy/jest-puppeteer": "^1.0.0",
"babel-core": "^6.0.0",
"babel-jest": "^21.2.0",
"babel-preset-env": "^1.6.0",
"@daisy/jest-env-puppeteer": "^1.2.0-beta.15",
"@daisy/jest-puppeteer": "^1.2.0-beta.15",
"@jest-runner/electron": "^3.0.1",
"babel-core": "^6.26.3",
"babel-jest": "^26.6.3",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"chalk": "^2.3.0",
"cross-env": "^5.2.0",
"cross-spawn": "^5.1.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.3.0",
"glob": "^7.1.2",
"chalk": "^4.1.0",
"cpy-cli": "^3.1.1",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"glob": "^7.1.6",
"i18next-json-sync": "^2.3.1",
"jest": "21.3.0-beta.10",
"lerna": "2.8",
"micromatch": "^3.1.4",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.1",
"snyk": "^1.56.0",
"standard-version": "^4.2.0",
"strip-ansi": "^4.0.0",
"uglify-js": "^3.0.8",
"watch": "^1.0.2"
"jest": "^26.6.3",
"lerna": "^4.0.0",
"micromatch": "^4.0.2",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2",
"strip-ansi": "^6.0.0"
},
"scripts": {
"axe-dev": "cpy \"../axe-core_DAISY/axe.js\" \"node_modules/@daisy/axe-core-for-ace/\" && cpy \"../axe-core_DAISY/axe.min.js\" \"node_modules/@daisy/axe-core-for-ace/\" && cpy \"../axe-core_DAISY/axe.d.ts\" \"node_modules/@daisy/axe-core-for-ace/\" && cpy \"../axe-core_DAISY/locales/*.*\" \"node_modules/@daisy/axe-core-for-ace/locales/\" && cpy \"../axe-core_DAISY/package.json\" \"node_modules/@daisy/axe-core-for-ace/\"",
"ace": "node ./packages/ace-cli/bin/ace.js",
"clean": "yarn run clean-libs",
"ace-electron": "electron ./packages/ace-axe-runner-electron/lib/cli.js",
"clean": "yarn clean-libs",
"clean-libs": "rimraf packages/*/lib",
"clean-node-modules": "rimraf packages/*/node_modules && rimraf node_modules",
"clean-all": "yarn run clean-libs && yarn run clean-node-modules",
"prebuild": "yarn run clean-libs",
"clean-all": "yarn clean-libs && yarn clean-node-modules",
"prebuild": "yarn clean-libs",
"build": "cross-env VERBOSE=1 node ./scripts/build.js",
"docs": "echo docs script not implemented",
"lint": "echo lint script not implemented",
"postinstall": "yarn run build",
"test": "jest",
"watch": "yarn run build && node ./scripts/watch.js",
"postinstall": "yarn npmVersionsCheck && yarn build && yarn patchElectronJestRunner",
"patchJestForTravis": "yarn patchJestForTravis1 && yarn patchJestForTravis2",
"patchJestForTravis1": "node scripts/replace-in-file.js node_modules/jest-environment-node/build/index.js \"function _fakeTimers\\(\\) {\" \"function _fakeTimersLegacyFakeTimers() { const data = require('@jest/fake-timers/build/legacyFakeTimers'); _fakeTimersLegacyFakeTimers = function () { return data; }; return data; } function _fakeTimersModernFakeTimers() { const data = require('@jest/fake-timers/build/modernFakeTimers'); _fakeTimersModernFakeTimers = function () { return data; }; return data; } function _fakeTimers() {\"",
"patchJestForTravis2": "node scripts/replace-in-file.js node_modules/jest-environment-node/build/index.js \"_fakeTimers\\(\\).LegacyFakeTimers\" \"_fakeTimersLegacyFakeTimers().default || _fakeTimersLegacyFakeTimers()\" && node scripts/replace-in-file.js node_modules/jest-environment-node/build/index.js \"_fakeTimers\\(\\).ModernFakeTimers\" \"_fakeTimersModernFakeTimers().default || _fakeTimersModernFakeTimers()\"",
"npmVersionsCheck": "node ./scripts/npm-versions-check.js",
"patchElectronJestRunner": "yarn patchElectronJestRunner1",
"patchElectronJestRunner1": "echo \";_electron.app.allowRendererProcessReuse = true;\" >> \"./node_modules/@jest-runner/electron/build/electron_process_injected_code.js\"",
"patchElectronJestRunner2": "node scripts/replace-in-file.js \"./node_modules/jest-runner/node_modules/jest-runtime/build/index.js\" \"_defineProperty\\(this, '_hasWarnedAboutRequireCacheModification', false\\);\" \"_defineProperty(this, '_hasWarnedAboutRequireCacheModification', true);\"",
"test": "cross-env JEST_TESTS=1 jest --config=jest.config-puppeteer.js --runInBand --bail=1 --no-cache",
"test-cli": "cross-env JEST_TESTS=1 jest --config=jest.config-cli.js --runInBand --bail=1 --no-cache",
"test-electron": "cross-env JEST_TESTS=1 AXE_ELECTRON_RUNNER=true jest --config=jest.config-electron.js --runInBand --bail=1 --no-cache",
"test-electron-cli": "cross-env JEST_TESTS=1 AXE_ELECTRON_RUNNER=true jest --config=jest.config-cli.js --runInBand --bail=1 --no-cache",
"test-all": "yarn test && yarn test-cli && yarn test-electron && yarn test-electron-cli",
"watch": "yarn build && node ./scripts/watch.js",
"i18n-sort": "node ./scripts/locales-sort.js",
"i18n-scan-ace-report": "node ./scripts/translate-scan.js \"packages/ace-report/src\" \"packages/ace-report/src/l10n/locales/temp.json\" && sync-i18n --files 'packages/ace-report/src/l10n/locales/*.json' --primary temp --languages en fr pt_BR es da --space 4 --finalnewline --newkeysempty && rimraf \"packages/ace-report/src/l10n/locales/temp.json\"",
"i18n-scan-ace-report-axe": "node ./scripts/translate-scan.js \"packages/ace-report-axe/src\" \"packages/ace-report-axe/src/l10n/locales/temp.json\" && sync-i18n --files 'packages/ace-report-axe/src/l10n/locales/*.json' --primary temp --languages en fr pt_BR es da --space 4 --finalnewline --newkeysempty && rimraf \"packages/ace-report-axe/src/l10n/locales/temp.json\"",
"i18n-scan-ace-core": "node ./scripts/translate-scan.js \"packages/ace-core/src\" \"packages/ace-core/src/l10n/locales/temp.json\" && sync-i18n --files 'packages/ace-core/src/l10n/locales/*.json' --primary temp --languages en fr pt_BR es da --space 4 --finalnewline --newkeysempty && rimraf \"packages/ace-core/src/l10n/locales/temp.json\"",
"i18n-scan": "npm run i18n-scan-ace-report && npm run i18n-scan-ace-report-axe && npm run i18n-scan-ace-core",
"i18n-check": "sync-i18n --files 'packages/**/src/l10n/locales/*.json' --primary en --languages fr pt_BR es da --space 4 --finalnewline --newkeysempty"
},
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>/tests/jest-setup.js",
"testEnvironment": "node"
"i18n-check": "sync-i18n --files 'packages/**/src/l10n/locales/*.json' --primary en --languages fr pt_BR es da --space 4 --finalnewline --newkeysempty",
"ace-app-prepare": "rm -f yarn.lock && rm -rf packages/*/lib && rm -rf packages/*/node_modules && rm -rf node_modules && yarn install && rm -rf packages/*/node_modules/@daisy && rm -rf node_modules/@daisy && yarn build && yarn upgrade && yarn patchElectronJestRunner && yarn npmVersionsCheck && git status && git --no-pager diff"
}
}
33 changes: 33 additions & 0 deletions packages/ace-axe-runner-electron/bin/ace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

var electron = require('electron')

var proc = require('child_process')

var path = require('path')

// console.log(process.argv);
// console.log(process.cwd());
// console.log(__dirname);
var args = [].concat(path.resolve(__dirname, "../lib/cli.js"), process.argv.slice(2))
// console.log(args);

var child = proc.spawn(electron, args, { stdio: 'inherit', windowsHide: false })
child.on('close', function (code, signal) {
if (code === null) {
console.error(electron, 'exited with signal', signal)
process.exit(1)
}
process.exit(code)
})

const handleTerminationSignal = function (signal) {
process.on(signal, function signalHandler () {
if (!child.killed) {
child.kill(signal)
}
})
}

handleTerminationSignal('SIGINT')
handleTerminationSignal('SIGTERM')
40 changes: 40 additions & 0 deletions packages/ace-axe-runner-electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@daisy/ace-axe-runner-electron",
"version": "1.2.0-beta.15",
"engines": {
"node": ">=10.0.0",
"yarn": "^1.22.5",
"npm": ">=6.14.12"
},
"description": "Electron-based Axe runner for Ace",
"author": {
"name": "DAISY developers",
"organization": "DAISY Consortium",
"url": "http://www.daisy.org/"
},
"repository": {
"type": "git",
"url": "https://github.com/daisy/ace",
"directory": "packages/ace-axe-runner-electron"
},
"bugs": {
"url": "https://github.com/daisy/ace/issues"
},
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"@daisy/ace-cli-shared": "^1.2.0-beta.15",
"express": "^4.17.1",
"portfinder": "^1.0.28",
"selfsigned": "^1.10.8",
"uuid": "^8.3.2"
},
"devDependencies": {
"electron": "^12.0.2",
"json": "^10.0.0",
"json-diff": "^0.5.4"
},
"publishConfig": {
"access": "public"
}
}
83 changes: 83 additions & 0 deletions packages/ace-axe-runner-electron/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

const electron = require('electron');
const app = electron.app;
// const ipcMain = electron.ipcMain;
// const ipcRenderer = electron.ipcRenderer;

// Removes the deprecation warning message in the console
// https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = true;

const EventEmitter = require('events');
class ElectronMockMainRendererEmitter extends EventEmitter {}
const eventEmmitter = new ElectronMockMainRendererEmitter();
eventEmmitter.send = eventEmmitter.emit;
eventEmmitter.ace_notElectronIpcMainRenderer = true;

const CONCURRENT_INSTANCES = 4; // same as the Puppeteer Axe runner

const axeRunnerElectronFactory = require('@daisy/ace-axe-runner-electron');
const axeRunner = axeRunnerElectronFactory.createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES);

const prepareLaunch = require('./init').prepareLaunch;
prepareLaunch(eventEmmitter, CONCURRENT_INSTANCES);

const cli = require('@daisy/ace-cli-shared');

const LOG_DEBUG = false;
const ACE_LOG_PREFIX = "[ACE-AXE]";

if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner CLI launch...`);

// let win;
// app.whenReady().then(() => {
app.on('ready', async () => {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner CLI app ready.`);

// win = new BrowserWindow(
// {
// show: false,
// webPreferences: {
// allowRunningInsecureContent: false,
// contextIsolation: false,
// nodeIntegration: true,
// nodeIntegrationInWorker: false,
// sandbox: false,
// webSecurity: true,
// webviewTag: false,
// }
// }
// );
// // win.maximize();
// // let sz = win.getSize();
// // const sz0 = sz[0];
// // const sz1 = sz[1];
// // win.unmaximize();
// // // open a window that's not quite full screen ... makes sense on mac, anyway
// // win.setSize(Math.min(Math.round(sz0 * .75),1200), Math.min(Math.round(sz1 * .85), 800));
// // // win.setPosition(Math.round(sz[0] * .10), Math.round(sz[1] * .10));
// // win.setPosition(Math.round(sz0*0.5-win.getSize()[0]*0.5), Math.round(sz1*0.5-win.getSize()[1]*0.5));
// // win.show();

// win.loadURL(`file://${__dirname}/index.html`);
// win.on('closed', function () {
// if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner win closed.`);
// });

if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner run...`);
await cli.run(axeRunner, app.exit, (typeof process.env.JEST_TESTS !== "undefined" ? "ace-tests-cli-electron.log" : "ace-cli-electron.log")); // const exitCode = app.quit();
});

app.on('activate', function () {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner app activate.`);
});
app.on('window-all-closed', function () {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner app window-all-closed.`);
});
app.on('before-quit', function() {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner app before-quit.`);
});
app.on('quit', () => {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner app quit.`);
});
Loading

0 comments on commit e974684

Please sign in to comment.