Skip to content

Commit 4acb78f

Browse files
committed
Various minor cleanup
1 parent eda412c commit 4acb78f

35 files changed

+95
-98
lines changed

test/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ test('babel require hook only applies to the test file', t => {
141141
test('throwing a anonymous function will report the function to the console', t => {
142142
execCli('fixture/throw-anonymous-function.js', (err, stdout, stderr) => {
143143
t.ok(err);
144-
t.match(stderr, /function \(\) \{\}/);
144+
t.match(stderr, /\(\) => \{\}/);
145145
// TODO(jamestalmage)
146146
// t.ok(/1 uncaught exception[^s]/.test(stdout));
147147
t.end();
+18-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
'use strict';
2+
const fs = require('fs');
3+
const path = require('path');
4+
const babel = require('babel-core');
25

3-
var babel = require('babel-core');
4-
var fs = require('fs');
5-
var path = require('path');
6+
const transformed = babel.transform(`
7+
import {mapFile} from 'source-map-fixtures';
8+
import test from '../../';
69
7-
var transformed = babel.transform([
8-
"import { mapFile } from 'source-map-fixtures'",
9-
"import test from '../../'",
10-
"const fixture = mapFile('throws').require()",
11-
// The uncaught exception is passed to the corresponding cli test. The line
12-
// numbers from the 'throws' fixture (which uses a map file), as well as the
13-
// line of the fixture.run() call, should match the source lines from this
14-
// string.
15-
"test('throw an uncaught exception', t => {",
16-
" setImmediate(run)",
17-
"})",
18-
"const run = () => fixture.run()"
19-
].join('\n'), {
10+
const fixture = mapFile('throws').require();
11+
12+
// The uncaught exception is passed to the corresponding cli test. The line
13+
// numbers from the 'throws' fixture (which uses a map file), as well as the
14+
// line of the fixture.run() call, should match the source lines from this
15+
// string.
16+
test('throw an uncaught exception', t => {
17+
setImmediate(run);
18+
})
19+
const run = () => fixture.run();
20+
`, {
2021
filename: 'source-map-initial-input.js',
2122
sourceMaps: true
2223
});
@@ -27,4 +28,5 @@ fs.writeFileSync(
2728
fs.writeFileSync(
2829
path.join(__dirname, 'source-map-initial.js.map'),
2930
JSON.stringify(transformed.map));
31+
3032
console.log('Generated source-map-initial.js');

test/fixture/async-await.js

-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ import test from '../../';
22

33
test('async function', async function (t) {
44
t.plan(1);
5-
65
const value = await Promise.resolve(1);
7-
86
t.is(value, 1);
97
});
108

119
test('arrow async function', async t => {
1210
t.plan(1);
13-
1411
const value = await Promise.resolve(1);
15-
1612
t.is(value, 1);
1713
});

test/fixture/ava-paths/target/test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
2-
/* eslint-disable import/no-unresolved */
1+
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved */
32
import test from 'ava';
43

5-
test(t => t.pass());
4+
test(t => {
5+
t.pass();
6+
});

test/fixture/babel-plugin-foo-to-bar.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
module.exports = function (babel) {
2-
var t = babel.types;
1+
'use strict';
2+
3+
function isRequire(path) {
4+
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
5+
}
6+
7+
module.exports = babel => {
8+
const t = babel.types;
39

410
return {
511
visitor: {
6-
CallExpression: function (path) {
12+
CallExpression: path => {
713
// skip require calls
814
var firstArg = path.get('arguments')[0];
15+
916
if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && /foo/i.test(firstArg.node.value)) {
1017
firstArg.replaceWith(t.stringLiteral(firstArg.node.value.replace('foo', 'bar').replace('FOO', 'BAR')));
1118
}
1219
}
1320
}
1421
};
1522
};
16-
17-
function isRequire(path) {
18-
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
19-
}

test/fixture/babel-plugin-test-capitalizer.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
module.exports = function (babel) {
2-
var t = babel.types;
1+
'use strict';
2+
3+
function isRequire(path) {
4+
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
5+
}
6+
7+
module.exports = babel => {
8+
const t = babel.types;
39

410
return {
511
visitor: {
6-
CallExpression: function (path) {
12+
CallExpression: path => {
713
// skip require calls
8-
var firstArg = path.get('arguments')[0];
14+
const firstArg = path.get('arguments')[0];
15+
916
if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && !/repeated test/.test(firstArg.node.value)) {
1017
firstArg.replaceWith(t.stringLiteral(firstArg.node.value.toUpperCase()));
1118
}
1219
}
1320
}
1421
};
1522
};
16-
17-
function isRequire(path) {
18-
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
19-
}
+15-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
/*
23
A Babel plugin that causes each AVA test to be duplicated with a new title.
34
@@ -11,28 +12,31 @@
1112
This is used by some integration tests to validate correct handling of Babel config options.
1213
*/
1314

14-
function plugin(babel) {
15-
var t = babel.types;
16-
var anonCount = 1;
15+
module.exports = babel => {
16+
const t = babel.types;
17+
const anonCount = 1;
1718

1819
return {
1920
visitor: {
20-
CallExpression: function (path) {
21-
var node = path.node;
22-
var callee = node.callee;
23-
var args = node.arguments;
21+
CallExpression: path => {
22+
const node = path.node;
23+
const callee = node.callee;
24+
let args = node.arguments;
25+
2426
if (callee.type === 'Identifier' && callee.name === 'test') {
2527
if (args.length === 1) {
26-
args = [t.StringLiteral('repeated test: anonymous' + anonCount++), args[0]];
28+
args = [t.StringLiteral(`repeated test: anonymous${anonCount++}`), args[0]];
2729
} else if (args.length === 2 && args[0].type === 'StringLiteral') {
2830
if (/^repeated test/.test(args[0].value)) {
2931
return;
3032
}
33+
3134
args = args.slice();
32-
args[0] = t.StringLiteral('repeated test: ' + args[0].value);
35+
args[0] = t.StringLiteral(`repeated test: ${args[0].value}`);
3336
} else {
34-
throw new Error('the plugin does not know how to handle this call to test');
37+
throw new Error('The plugin does not know how to handle this call to test');
3538
}
39+
3640
path.insertAfter(t.CallExpression(
3741
t.Identifier('test'),
3842
args
@@ -41,6 +45,4 @@ function plugin(babel) {
4145
}
4246
}
4347
};
44-
}
45-
46-
module.exports = plugin;
48+
};

test/fixture/caching/test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import test from '../../../'
1+
import test from '../../../';
22

3-
test(t => t.true(2 + 2 === 4));
3+
test(t => {
4+
t.true(2 + 2 === 4);
5+
});
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import test from '../../';
22

3-
test.beforeEach(t => t.context = 'bar');
3+
test.beforeEach(t => {
4+
t.context = 'bar';
5+
});
46

5-
test.cb('callback mode', ({context: foo, ... t}) => {
7+
test.cb('callback mode', ({context: foo, ...t}) => {
68
t.is(foo, 'bar');
79
t.end();
810
});
911

10-
test.cb('callback mode #2', ({context: foo, end, ... t}) => {
12+
test.cb('callback mode #2', ({context: foo, end, ...t}) => {
1113
t.is(foo, 'bar');
1214
end();
1315
});
1416

15-
test('sync', ({context: foo, ... t}) => {
17+
test('sync', ({context: foo, ...t}) => {
1618
t.is(foo, 'bar');
1719
});
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from '../../';
22

33
test.only(t => {
4-
t.pass();
4+
t.pass();
55
});
66

77
test(t => {
8-
t.fail();
8+
t.fail();
99
});

test/fixture/exclusive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from '../../';
22

33
test.only(t => {
4-
t.pass();
4+
t.pass();
55
});

test/fixture/fake-timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from '../../';
21
import sinon from 'sinon';
2+
import test from '../../';
33

44
test(t => {
55
sinon.useFakeTimers(Date.now() + 10000);

test/fixture/generators.js

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import test from '../../';
22

33
test('generator function', function * (t) {
44
t.plan(1);
5-
65
const value = yield Promise.resolve(1);
7-
86
t.is(value, 1);
97
});

test/fixture/immediate-0-exit.js

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
'use strict';
12
process.exit(0);

test/fixture/immediate-3-exit.js

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
'use strict';
12
process.exit(3);

test/fixture/improper-t-throws-unhandled-rejection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test.cb(t => {
44
Promise.resolve().then(() => {
55
t.throws(throwSync());
66
});
7-
7+
88
setTimeout(t.end, 20);
99
});
1010

test/fixture/install-global.js

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
'use strict';
12
global.foo = 'bar';

test/fixture/long-running.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ test.cb('slow', t => {
44
setTimeout(t.end, 5000);
55
});
66

7-
test('fast', t => {
8-
9-
});
7+
test('fast', () => {});

test/fixture/loud-rejection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from '../../';
22

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

66
setTimeout(() => {
77
t.end();

test/fixture/node-paths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import test from '../../';
21
import foo from 'nested/foo';
32
import bar from 'path/bar';
3+
import test from '../../';
44

55
test('relative require', t => {
66
t.is(foo, 'bar');
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
'use strict';
12
module.exports = 'baz';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
'use strict';
12
module.exports = 'bar';

test/fixture/observable.js

-13
This file was deleted.

test/fixture/pkg-conf/defaults/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../../../'
1+
import test from '../../../../';
22

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

test/fixture/pkg-conf/pkg-overrides/actual.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from '../../../../';
21
import path from 'path';
2+
import test from '../../../../';
33

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

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
'use strict';
2-
32
module.exports = 'foo';

test/fixture/pkg-conf/precedence/c.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from '../../../../';
21
import path from 'path';
2+
import test from '../../../../';
33

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

Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
module.exports = "bar";
1+
'use strict';
2+
module.exports = 'bar';
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
'use strict';
2-
32
module.exports = 'foo';

test/fixture/power-assert.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@ import test from '../../';
22

33
test.serial(t => {
44
const a = 'foo';
5-
65
t.true(a === 'bar');
76
});
87

98
test.serial(t => {
109
const a = 'bar';
11-
1210
t.true(a === 'foo', 'with message');
1311
});
1412

1513
test.serial(t => {
1614
const o = {};
17-
1815
t.true(o === {...o});
1916
});
2017

2118
test.serial(t => {
22-
const React = { createElement: function(type) { return type } }
19+
const React = {
20+
createElement: type => type
21+
};
2322

2423
t.true(<div /> === <span />);
2524
});

test/fixture/serial.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from '../../';
22

3-
var tests = [];
3+
const tests = [];
44

55
test.cb('first', t => {
66
setTimeout(() => {

0 commit comments

Comments
 (0)