Skip to content

Commit

Permalink
Switch to intern-dev, cleanup tests and examples
Browse files Browse the repository at this point in the history
- Switch to intern-dev for building
- Add separate tsconfig for tests -- tests are built as UMD, while main
  source is built as CommonJS.
- Improve TS syntax
  • Loading branch information
jason0x43 committed Feb 14, 2017
1 parent 9a309cc commit 7474d28
Show file tree
Hide file tree
Showing 30 changed files with 145 additions and 470 deletions.
2 changes: 1 addition & 1 deletion examples/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "intern-a11y-JS-example",
"devDependencies": {
"intern": "^3.3.0",
"intern-a11y": "file:../../dist"
"intern-a11y": "file:../../_build/src"
},
"scripts": {
"test": "node support/test.js",
Expand Down
9 changes: 7 additions & 2 deletions examples/js/support/clean.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
var shell = require('shelljs');
shell.rm('-f', 'a11y-report.html');
var fs = require('fs');
try {
fs.unlinkSync('a11y-report.html');
}
catch (error) {
// ignore
}
2 changes: 1 addition & 1 deletion examples/js/tests/intern.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ define([ 'intern' ], function (intern) {

reporters: [
{
id: 'dojo/node!intern-a11y/src/A11yReporter',
id: 'dojo/node!intern-a11y/A11yReporter',
filename: 'a11y-report.html'
},
intern.mode === 'client' ? 'Console' : 'Runner'
Expand Down
9 changes: 4 additions & 5 deletions examples/ts/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "intern-a11y-TS-example",
"devDependencies": {
"intern": "~3.4.0",
"intern-a11y": "file:../../dist",
"shelljs": "0.7.4",
"@types/es6-promise": "0.0.31"
"intern": "^3.4.0",
"intern-a11y": "file:../../_build/src",
"typescript": "~2.1.0"
},
"scripts": {
"test": "node support/test.js",
"build": "node support/build.js",
"build": "tsc",
"clean": "node support/clean.js"
}
}
2 changes: 0 additions & 2 deletions examples/ts/support/build.js

This file was deleted.

11 changes: 2 additions & 9 deletions examples/ts/support/clean.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
var shell = require('shelljs');

if (process.argv[2] === 'all') {
shell.exec('git clean -d -x -f -e "intern-local.ts"')
}
else {
shell.rm('-f', 'tests/*.js');
shell.rm('-f', 'a11y-report.html');
}
var execSync = require('child_process').execSync;
execSync('git clean -d -x -f -e "intern-local.ts" -e "node_modules/"');
6 changes: 3 additions & 3 deletions examples/ts/tests/axe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { services } from 'intern-a11y';
import * as Test from 'intern/lib/Test';
import * as path from 'path';
import Test = require('intern/lib/Test');
import { join } from 'path';
import { assert } from 'chai';
import { TestModuleInit } from './interfaces';
import { IRequire } from 'dojo/loader';
Expand All @@ -26,7 +26,7 @@ export const init: TestModuleInit = function (registerSuite) {
'file name'(this: Test) {
return axe.check({
remote: this.remote,
source: path.join(__dirname, 'data', 'page.html')
source: join(__dirname, 'data', 'page.html')
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/tests/intern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const filterErrorStack = true;

export const reporters = [
{
id: 'dojo/node!intern-a11y/src/A11yReporter',
id: 'dojo/node!intern-a11y/A11yReporter',
filename: 'a11y-report.html'
},
intern.mode === 'client' ? 'Console' : 'Runner'
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/tests/nodeSuite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This module must be loaded by an AMD loader

import * as registerSuite from 'intern!object';
import registerSuite = require('intern!object');
import { TestModule } from './interfaces';
import { IRequire } from 'dojo/loader';

Expand Down
4 changes: 2 additions & 2 deletions examples/ts/tests/tenon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { services } from 'intern-a11y';
import * as path from 'path';
import { join } from 'path';
import { assert } from 'chai';
import { TestModuleInit } from './interfaces';

Expand All @@ -18,7 +18,7 @@ export const init: TestModuleInit = function (registerSuite) {
},

'file name'() {
return tenon.check({ source: path.join(__dirname, 'data', 'page.html') });
return tenon.check({ source: join(__dirname, 'data', 'page.html') });
}
});
}
3 changes: 2 additions & 1 deletion examples/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"noImplicitAny": true,
"noImplicitThis": true,
"removeComments": true,
"preserveConstEnums": true
"preserveConstEnums": true,
"target": "ES5"
},
"include": [
"./tests/**/*.ts"
Expand Down
36 changes: 23 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "intern-a11y",
"version": "0.1.2-pre",
"main": "src/index.js",
"types": "src/index.d.ts",
"main": "index.js",
"types": "index.d.ts",
"description": "Intern-a11y. An accessibility testing helper for Intern.",
"repository": {
"type": "git",
Expand All @@ -14,12 +14,9 @@
},
"devDependencies": {
"@types/es6-promise": "0.0.31",
"@types/shelljs": "0.3.32",
"chokidar": "1.6.0",
"intern": "~3.4.0",
"shelljs": "0.7.4",
"typescript": "~2.0.0",
"semver": "5.3.0"
"intern-dev": "https://github.com/theintern/intern-dev/releases/download/0.1.5/intern-dev-0.1.5.tgz",
"typescript": "~2.1.0"
},
"peerDependencies": {
"intern": "~3.4.0"
Expand All @@ -34,10 +31,23 @@
],
"homepage": "http://github.com/theintern/intern-a11y",
"scripts": {
"build": "node ./support/build.js",
"clean": "node ./support/clean.js",
"test": "node ./support/test.js",
"watch": "node ./support/watch.js",
"release": "node ./support/release.js"
"build": "intern-dev-clean && intern-dev-build",
"clean": "intern-dev-clean",
"lint": "intern-dev-lint",
"release": "intern-dev-release",
"test": "intern-dev-build && NODE_PATH=_build intern-dev-test",
"watch": "intern-dev-watch"
},
"internDev": {
"resources": {
".": [
"tests/**/*.html"
]
},
"configs": [
"tsconfig.json",
"tests/tsconfig.json"
],
"publishDir": "_build/src"
}
}
}
16 changes: 8 additions & 8 deletions src/A11yReporter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Test from 'intern/lib/Test';
import * as path from 'path';
import * as fs from 'fs';
import Test = require('intern/lib/Test');
import { join } from 'path';
import { mkdirSync, writeFile, writeFileSync } from 'fs';
import { A11yResults, A11yViolation } from './common';

class A11yReporter {
Expand All @@ -24,7 +24,7 @@ class A11yReporter {
else {
// ReporterManager will already have created dirname(this.config.filename)
try {
fs.mkdirSync(this.filename);
mkdirSync(this.filename);
}
catch (error) {
if (error.code !== 'EEXIST') {
Expand All @@ -45,22 +45,22 @@ class A11yReporter {
this.report.push(content);
}
else {
const filename = path.join(this.filename, sanitizeFilename(test.id + '.html'));
fs.writeFileSync(filename, renderReport(content));
const filename = join(this.filename, sanitizeFilename(test.id + '.html'));
writeFileSync(filename, renderReport(content));
}
}
}

runEnd() {
if (this.report) {
fs.writeFileSync(this.filename, renderReport(this.report.join('')));
writeFileSync(this.filename, renderReport(this.report.join('')));
}
}

static writeReport(filename: string, results: A11yResults, id: string) {
return new Promise(function (resolve, reject) {
const content = renderResults(results, id);
fs.writeFile(filename, renderReport(content), function (error) {
writeFile(filename, renderReport(content), function (error) {
if (error) {
reject(error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/_tenon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { A11yResults } from '../common';
import * as fs from 'fs';
import { statSync } from 'fs';

export interface TenonResults {
apiErrors: any[];
Expand Down Expand Up @@ -140,7 +140,7 @@ export function toA11yResults(tenonResults: TenonResults): A11yResults {

export function fileExists(filename: string) {
try {
return fs.statSync(filename).isFile();
return statSync(filename).isFile();
}
catch (error) {
if (error.code === 'ENOENT') {
Expand Down
6 changes: 3 additions & 3 deletions src/services/axe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as Command from 'leadfoot/Command';
import { readFileSync } from 'fs';
import { A11yResults, A11yError } from '../common';
import { AxeResults, toA11yResults } from './_axe';
import Command = require('leadfoot/Command');

export interface AxeTestOptions {
config?: {
Expand Down Expand Up @@ -54,7 +54,7 @@ export function createChecker(options?: AxeTestOptions) {
return function (this: Command<any>) {
options = options || {};
const axePath = require.resolve('axe-core/axe.min');
const axeScript = fs.readFileSync(axePath, { encoding: 'utf8' });
const axeScript = readFileSync(axePath, { encoding: 'utf8' });
const axeContext = options.context;

const config = options.config;
Expand Down
12 changes: 6 additions & 6 deletions src/services/tenon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as https from 'https';
import * as querystring from 'querystring';
import * as fs from 'fs';
import { request as httpsRequest } from 'https';
import { stringify } from 'querystring';
import { readFileSync } from 'fs';
import { A11yError, A11yResults } from '../common';
import { TenonResults, toA11yResults, fileExists } from './_tenon';

Expand Down Expand Up @@ -58,16 +58,16 @@ export function check(options: TenonTestOptions) {
}
else if (fileExists(source)) {
// source is a file name
queryData.src = fs.readFileSync(source, { encoding: 'utf8' });
queryData.src = readFileSync(source, { encoding: 'utf8' });
}
else {
// source is raw data
queryData.src = source;
}

const data = querystring.stringify(queryData);
const data = stringify(queryData);

const request = https.request({
const request = httpsRequest({
host: 'tenon.io',
path: '/api/',
method: 'POST',
Expand Down
25 changes: 0 additions & 25 deletions support/build.js

This file was deleted.

13 changes: 0 additions & 13 deletions support/clean.js

This file was deleted.

Loading

0 comments on commit 7474d28

Please sign in to comment.