Skip to content

Commit

Permalink
Various minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 22, 2016
1 parent eda412c commit 8610723
Show file tree
Hide file tree
Showing 35 changed files with 95 additions and 98 deletions.
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test('babel require hook only applies to the test file', t => {
test('throwing a anonymous function will report the function to the console', t => {
execCli('fixture/throw-anonymous-function.js', (err, stdout, stderr) => {
t.ok(err);
t.match(stderr, /function \(\) \{\}/);
t.match(stderr, /\(\) => \{\}/);
// TODO(jamestalmage)
// t.ok(/1 uncaught exception[^s]/.test(stdout));
t.end();
Expand Down
34 changes: 18 additions & 16 deletions test/fixture/_generate_source-map-initial.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
'use strict';
const fs = require('fs');
const path = require('path');
const babel = require('babel-core');

var babel = require('babel-core');
var fs = require('fs');
var path = require('path');
const transformed = babel.transform(`
import {mapFile} from 'source-map-fixtures';
import test from '../../';
var transformed = babel.transform([
"import { mapFile } from 'source-map-fixtures'",
"import test from '../../'",
"const fixture = mapFile('throws').require()",
// The uncaught exception is passed to the corresponding cli test. The line
// numbers from the 'throws' fixture (which uses a map file), as well as the
// line of the fixture.run() call, should match the source lines from this
// string.
"test('throw an uncaught exception', t => {",
" setImmediate(run)",
"})",
"const run = () => fixture.run()"
].join('\n'), {
const fixture = mapFile('throws').require();
// The uncaught exception is passed to the corresponding cli test. The line
// numbers from the 'throws' fixture (which uses a map file), as well as the
// line of the fixture.run() call, should match the source lines from this
// string.
test('throw an uncaught exception', t => {
setImmediate(run);
})
const run = () => fixture.run();
`, {
filename: 'source-map-initial-input.js',
sourceMaps: true
});
Expand All @@ -27,4 +28,5 @@ fs.writeFileSync(
fs.writeFileSync(
path.join(__dirname, 'source-map-initial.js.map'),
JSON.stringify(transformed.map));

console.log('Generated source-map-initial.js');
4 changes: 0 additions & 4 deletions test/fixture/async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import test from '../../';

test('async function', async function (t) {
t.plan(1);

const value = await Promise.resolve(1);

t.is(value, 1);
});

test('arrow async function', async t => {
t.plan(1);

const value = await Promise.resolve(1);

t.is(value, 1);
});
7 changes: 4 additions & 3 deletions test/fixture/ava-paths/target/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved */
import test from 'ava';

test(t => t.pass());
test(t => {
t.pass();
});
17 changes: 10 additions & 7 deletions test/fixture/babel-plugin-foo-to-bar.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
module.exports = function (babel) {
var t = babel.types;
'use strict';

function isRequire(path) {
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
}

module.exports = babel => {
const t = babel.types;

return {
visitor: {
CallExpression: function (path) {
CallExpression: path => {
// skip require calls
var firstArg = path.get('arguments')[0];

if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && /foo/i.test(firstArg.node.value)) {
firstArg.replaceWith(t.stringLiteral(firstArg.node.value.replace('foo', 'bar').replace('FOO', 'BAR')));
}
}
}
};
};

function isRequire(path) {
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
}
19 changes: 11 additions & 8 deletions test/fixture/babel-plugin-test-capitalizer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
module.exports = function (babel) {
var t = babel.types;
'use strict';

function isRequire(path) {
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
}

module.exports = babel => {
const t = babel.types;

return {
visitor: {
CallExpression: function (path) {
CallExpression: path => {
// skip require calls
var firstArg = path.get('arguments')[0];
const firstArg = path.get('arguments')[0];

if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && !/repeated test/.test(firstArg.node.value)) {
firstArg.replaceWith(t.stringLiteral(firstArg.node.value.toUpperCase()));
}
}
}
};
};

function isRequire(path) {
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
}
28 changes: 15 additions & 13 deletions test/fixture/babel-plugin-test-doubler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
A Babel plugin that causes each AVA test to be duplicated with a new title.
Expand All @@ -11,28 +12,31 @@
This is used by some integration tests to validate correct handling of Babel config options.
*/

function plugin(babel) {
var t = babel.types;
var anonCount = 1;
module.exports = babel => {
const t = babel.types;
const anonCount = 1;

return {
visitor: {
CallExpression: function (path) {
var node = path.node;
var callee = node.callee;
var args = node.arguments;
CallExpression: path => {
const node = path.node;
const callee = node.callee;
let args = node.arguments;

if (callee.type === 'Identifier' && callee.name === 'test') {
if (args.length === 1) {
args = [t.StringLiteral('repeated test: anonymous' + anonCount++), args[0]];
args = [t.StringLiteral(`repeated test: anonymous${anonCount++}`), args[0]];
} else if (args.length === 2 && args[0].type === 'StringLiteral') {
if (/^repeated test/.test(args[0].value)) {
return;
}

args = args.slice();
args[0] = t.StringLiteral('repeated test: ' + args[0].value);
args[0] = t.StringLiteral(`repeated test: ${args[0].value}`);
} else {
throw new Error('the plugin does not know how to handle this call to test');
throw new Error('The plugin does not know how to handle this call to test');
}

path.insertAfter(t.CallExpression(
t.Identifier('test'),
args
Expand All @@ -41,6 +45,4 @@ function plugin(babel) {
}
}
};
}

module.exports = plugin;
};
6 changes: 4 additions & 2 deletions test/fixture/caching/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import test from '../../../'
import test from '../../../';

test(t => t.true(2 + 2 === 4));
test(t => {
t.true(2 + 2 === 4);
});
10 changes: 6 additions & 4 deletions test/fixture/destructuring-public-api.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import test from '../../';

test.beforeEach(t => t.context = 'bar');
test.beforeEach(t => {
t.context = 'bar';
});

test.cb('callback mode', ({context: foo, ... t}) => {
test.cb('callback mode', ({context: foo, ...t}) => {
t.is(foo, 'bar');
t.end();
});

test.cb('callback mode #2', ({context: foo, end, ... t}) => {
test.cb('callback mode #2', ({context: foo, end, ...t}) => {
t.is(foo, 'bar');
end();
});

test('sync', ({context: foo, ... t}) => {
test('sync', ({context: foo, ...t}) => {
t.is(foo, 'bar');
});
4 changes: 2 additions & 2 deletions test/fixture/exclusive-nonexclusive.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import test from '../../';

test.only(t => {
t.pass();
t.pass();
});

test(t => {
t.fail();
t.fail();
});
2 changes: 1 addition & 1 deletion test/fixture/exclusive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from '../../';

test.only(t => {
t.pass();
t.pass();
});
2 changes: 1 addition & 1 deletion test/fixture/fake-timers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from '../../';
import sinon from 'sinon';
import test from '../../';

test(t => {
sinon.useFakeTimers(Date.now() + 10000);
Expand Down
2 changes: 0 additions & 2 deletions test/fixture/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import test from '../../';

test('generator function', function * (t) {
t.plan(1);

const value = yield Promise.resolve(1);

t.is(value, 1);
});
1 change: 1 addition & 0 deletions test/fixture/immediate-0-exit.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
process.exit(0);
1 change: 1 addition & 0 deletions test/fixture/immediate-3-exit.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
process.exit(3);
2 changes: 1 addition & 1 deletion test/fixture/improper-t-throws-unhandled-rejection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test.cb(t => {
Promise.resolve().then(() => {
t.throws(throwSync());
});

setTimeout(t.end, 20);
});

Expand Down
1 change: 1 addition & 0 deletions test/fixture/install-global.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
global.foo = 'bar';
4 changes: 1 addition & 3 deletions test/fixture/long-running.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ test.cb('slow', t => {
setTimeout(t.end, 5000);
});

test('fast', t => {

});
test('fast', () => {});
2 changes: 1 addition & 1 deletion test/fixture/loud-rejection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from '../../';

test.cb('creates an unhandled rejection', t => {
Promise.reject(new Error(`You can't handle this!`));
Promise.reject(new Error('You can\'t handle this!'));

setTimeout(() => {
t.end();
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/node-paths.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from '../../';
import foo from 'nested/foo';
import bar from 'path/bar';
import test from '../../';

test('relative require', t => {
t.is(foo, 'bar');
Expand Down
1 change: 1 addition & 0 deletions test/fixture/node-paths/deep/nested/path/bar.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
module.exports = 'baz';
1 change: 1 addition & 0 deletions test/fixture/node-paths/modules/nested/foo.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
module.exports = 'bar';
13 changes: 0 additions & 13 deletions test/fixture/observable.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/defaults/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from '../../../../'
import test from '../../../../';

const opts = JSON.parse(process.argv[2]);

Expand Down
2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/pkg-overrides/actual.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from '../../../../';
import path from 'path';
import test from '../../../../';

const opts = JSON.parse(process.argv[2]);

Expand Down
1 change: 0 additions & 1 deletion test/fixture/pkg-conf/pkg-overrides/required.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
'use strict';

module.exports = 'foo';
2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/precedence/c.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from '../../../../';
import path from 'path';
import test from '../../../../';

const opts = JSON.parse(process.argv[2]);

Expand Down
3 changes: 2 additions & 1 deletion test/fixture/pkg-conf/precedence/default-required.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = "bar";
'use strict';
module.exports = 'bar';
1 change: 0 additions & 1 deletion test/fixture/pkg-conf/precedence/required.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
'use strict';

module.exports = 'foo';
7 changes: 3 additions & 4 deletions test/fixture/power-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ import test from '../../';

test.serial(t => {
const a = 'foo';

t.true(a === 'bar');
});

test.serial(t => {
const a = 'bar';

t.true(a === 'foo', 'with message');
});

test.serial(t => {
const o = {};

t.true(o === {...o});
});

test.serial(t => {
const React = { createElement: function(type) { return type } }
const React = {
createElement: type => type
};

t.true(<div /> === <span />);
});
2 changes: 1 addition & 1 deletion test/fixture/serial.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from '../../';

var tests = [];
const tests = [];

test.cb('first', t => {
setTimeout(() => {
Expand Down
Loading

0 comments on commit 8610723

Please sign in to comment.