Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate PR for pending beta 3 issues #125

Merged
merged 6 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/ace-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@daisy/ace-config",
"version": "0.0.1",
"description": "Config utilities for Ace",
"author": {
"name": "DAISY developers",
"organization": "DAISY Consortium",
"url": "http://www.daisy.org/"
},
"repository": {
"type": "git",
"url": "https://github.com/daisy/ace"
},
"bugs": {
"url": "https://github.com/daisy/ace/issues"
},
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"conf": "^1.3.1",
"env-paths": "^1.0.0",
"lodash.mergewith": "^4.6.0"
},
"publishConfig": {
"access": "public"
}
}
60 changes: 60 additions & 0 deletions packages/ace-config/src/__tests__/config-store.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

const ConfigStore = require('../config-store');
const tmp = require('tmp');

tmp.setGracefulCleanup();

let conf;
const fixture = {
a: 1,
b: [2, 2],
c: { x: 3, y: 3 },
};

beforeEach(() => {
conf = new ConfigStore({ cwd: tmp.dirSync({ unsafeCleanup: true }).name });
});

test('config store is defined', () => {
expect(ConfigStore).toBeDefined();
});

test('.get 2-args to work as in parent', () => {
expect(conf.get('foo')).not.toBeDefined();
expect(conf.get('foo', 'bar')).toBe('bar');
conf.set('foo', fixture);
expect(conf.get('foo')).toEqual(fixture);
});

test('.get to ignore null or false merge mode', () => {
conf.set('foo', fixture);
expect(conf.get('foo', { d: 4 }, null)).toEqual(fixture);
expect(conf.get('foo', { d: 4 }, false)).toEqual(fixture);
});

test('.get merge mode to merge the defaults', () => {
conf.set('foo', fixture);
expect(conf.get('foo', { c: { z: 3 } }, true)).toEqual({
a: 1,
b: [2, 2],
c: { x: 3, y: 3, z: 3 },
});
});

test('.get merge mode override the defaults', () => {
conf.set('foo', fixture);
expect(conf.get('foo', { a: 'foo' }, true)).toEqual(fixture);
expect(conf.get('foo', { c: { x: 'foo' } }, true)).toEqual(fixture);
});

test('.get merge mode ignores non-object defaults', () => {
conf.set('foo', fixture);
expect(conf.get('foo', 'foo', true)).toEqual(fixture);
expect(conf.get('foo', null, true)).toEqual(fixture);
});

test('.get merge mode concatenates arrays', () => {
conf.set('foo', fixture);
expect(conf.get('foo', { b: ['x'] }, true)).toMatchObject({ b: ['x', 2, 2] });
});
29 changes: 29 additions & 0 deletions packages/ace-config/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const path = require('path');
const { config, paths, constants } = require('..');

test('config store is defined', () => {
expect(config).toBeDefined();
});

test('config file default name', () => {
expect(path.basename(config.path)).toEqual('config.json');
expect(path.basename(path.dirname(config.path))).toEqual('DAISY Ace');
});

test('paths are defined', () => {
expect(paths).toBeDefined();
expect(paths.config).toBeDefined();
expect(paths.data).toBeDefined();
expect(paths.log).toBeDefined();
expect(paths.temp).toBeDefined();
});

test('constants are defined', () => {
expect(constants).toBeDefined();
});

test('constants are as in constants.json', () => {
expect(constants.dirname).toBe('DAISY Ace');
});
20 changes: 20 additions & 0 deletions packages/ace-config/src/config-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const Conf = require('conf');
const merge = require('lodash.mergewith');

class ConfigStore extends Conf {

get(key, defaultValue, mergeMode) {
if (mergeMode && typeof defaultValue === 'object') {
return merge({}, defaultValue, super.get(key), (obj, val) => {
if (Array.isArray(obj)) {
return obj.concat(val);
}
});
}
return super.get(key, defaultValue);
}
}

module.exports = ConfigStore;
3 changes: 3 additions & 0 deletions packages/ace-config/src/constants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dirname": "DAISY Ace"
}
17 changes: 17 additions & 0 deletions packages/ace-config/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const envPaths = require('env-paths');
const constants = require('./constants');
const ConfigStore = require('./config-store');

const paths = envPaths(constants.dirname, { suffix: null });

const config = new ConfigStore({
cwd: paths.config,
});

module.exports = {
config,
constants: Object.freeze(constants),
paths,
};
29 changes: 29 additions & 0 deletions packages/ace-core/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const { config } = require('../../../scripts/build-utils');

function buildH5O() {
/**
* Wrap the browserified h5o in a function to temporarily undefine 'define'
* since Browserify and RequireJS otherwise don’t go along
* see: https://github.com/browserify/browserify/issues/790
*/
const vendorDir = path.resolve(__dirname, '..', config.buildDir, 'scripts/vendor');
const srcPath = path.resolve(require.resolve('h5o'), '../dist/outliner.min.js');
const destPath = path.resolve(vendorDir, 'outliner.min.js');

mkdirp.sync(path.dirname(destPath));
const ws = fs.createWriteStream(destPath);
const rs = fs.createReadStream(srcPath);
ws.write('(function () { var define = undefined;');
rs.pipe(ws, { end: false });
rs.on('end', () => {
ws.end('})();');
});
}

buildH5O();

5 changes: 3 additions & 2 deletions packages/ace-core/src/checker/checker-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const utils = require('@daisy/puppeteer-utils');

const scripts = [
path.resolve(require.resolve('axe-core'), '../axe.min.js'),
path.resolve(require.resolve('h5o'), '../dist/outliner.min.js'),
require.resolve('../scripts/vendor/outliner.min.js'),
require.resolve('../scripts/axe-patch-getselector.js'),
require.resolve('../scripts/axe-patch-arialookuptable.js'),
require.resolve('../scripts/axe-patch-dlitem.js'),
require.resolve('../scripts/ace-axe.js'),
require.resolve('../scripts/ace-extraction.js'),
];
Expand Down Expand Up @@ -74,7 +75,7 @@ async function checkSingle(spineItem, epub, browser) {
return results;
} catch (err) {
winston.debug(`Error when running HTML checks: ${err}`);
throw new Error('Failed to check HTML content');
throw new Error(`Failed to check Content Document '${spineItem.relpath}'`);
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/ace-core/src/scripts/axe-patch-dlitem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

(function axePatch(window) {
const axe = window.axe;
axe._audit.checks.dlitem.evaluate = function evaluate(node, options) {
return node.parentNode.nodeName.toUpperCase() === 'DL';
}
}(window));
2 changes: 1 addition & 1 deletion packages/ace-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"env-paths": "^1.0.0",
"@daisy/ace-config": "^0.0.1",
"fs-extra": "^4.0.2",
"winston": "^2.4.0"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/ace-logger/src/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"logging": {
"level": "info",
"fileName": "ace.log"
}
}
13 changes: 7 additions & 6 deletions packages/ace-logger/src/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
'use strict';

const envPaths = require('env-paths');
const { config, paths } = require('@daisy/ace-config');
const fs = require('fs-extra');
const path = require('path');
const winston = require('winston');
const defaults = require('./defaults');

const acePaths = envPaths('DAISY Ace', { suffix: null });
const logConfig = config.get('logging', defaults.logging);

module.exports.initLogger = function initLogger(options = {}) {
// Check logging directoy exists
if (!fs.existsSync(acePaths.log)) {
fs.ensureDirSync(acePaths.log);
if (!fs.existsSync(paths.log)) {
fs.ensureDirSync(paths.log);
}

// OS-dependant path to log file
const logfile = path.join(acePaths.log, 'ace.log');
const logfile = path.join(paths.log, logConfig.fileName);

// clear old log file
if (fs.existsSync(logfile)) {
fs.removeSync(logfile);
}

// set up logger
const level = (options.verbose) ? 'verbose' : 'info';
const level = (options.verbose) ? 'verbose' : logConfig.level;
winston.configure({
level,
transports: [
Expand Down
8 changes: 8 additions & 0 deletions scripts/build-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const path = require('path');

const PACKAGES_DIR = path.resolve(__dirname, '../packages');

const config = {
srcDir: 'src',
buildDir: 'lib',
jsPattern: '**/*.js',
ignorePattern: '**/*.test.js',
};

function listPackages() {
return fs
.readdirSync(PACKAGES_DIR)
Expand All @@ -13,6 +20,7 @@ function listPackages() {
}

module.exports = {
config,
listPackages,
PACKAGES_DIR,
};
14 changes: 7 additions & 7 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ const glob = require('glob');
const micromatch = require('micromatch');
const mkdirp = require('mkdirp');
const path = require('path');
const spawn = require('cross-spawn');

const { listPackages, PACKAGES_DIR } = require('./build-utils');

const config = {
srcDir: 'src',
buildDir: 'lib',
jsPattern: '**/*.js',
ignorePattern: '**/*.test.js',
};
const { config, listPackages, PACKAGES_DIR } = require('./build-utils');

const babelConfig = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '..', '.babelrc'), 'utf8'));
Expand Down Expand Up @@ -80,6 +75,11 @@ function buildPackage(pkg) {
process.stdout.write(` ${path.basename(pkg)} ${chalk.dim('...')}`);

files.forEach(file => buildFile(file, true));

const buildScript = path.resolve(pkg, 'scripts/build.js');
if (fs.existsSync(buildScript)) {
spawn.sync('node', [buildScript], { stdio: 'inherit' });
}
process.stdout.write(`${chalk.reset.bold.green(' ✓ Done')}\n`);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/__tests__/regression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ test('issue #85: failed to detect page markers from `epub:type`', async () => {
expect(report['earl:result']['earl:outcome']).toEqual('pass');
expect(report.properties.hasPageBreaks).toBe(true);
});

test('issue #108: HTML5Outline is not defined (RequireJS conflict)', async () => {
const report = await ace('../data/issue-108');
expect(report['earl:result']['earl:outcome']).toEqual('pass');
});

test('issue #114: Description list item does not have a <dl> parent element', async () => {
const report = await ace('../data/issue-114');
expect(report['earl:result']['earl:outcome']).toEqual('pass');
});
10 changes: 10 additions & 0 deletions tests/data/issue-108/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body>
<script src="require.js"></script>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/issue-108/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
24 changes: 24 additions & 0 deletions tests/data/issue-108/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<item id="requirejs" href="require.js" media-type="text/javascript"/>
</manifest>
<spine>
<itemref idref="content_001"/>
</spine>
</package>
5 changes: 5 additions & 0 deletions tests/data/issue-108/EPUB/require.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/data/issue-108/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/issue-108/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Loading