Skip to content

Commit 8955e15

Browse files
committed
Lint test fixtures
Work around xojs/xo#65 by invoking XO from within the `test/fixture` directory. Fix linting issues. Most were harmless, but it did turn out that `babel-plugin-test-doubler.js` no longer doubled tests.
1 parent fa4f73c commit 8955e15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+126
-126
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"node": ">=4"
4343
},
4444
"scripts": {
45-
"test": "xo && flow check test/flow-types && tsc -p test/ts-types && nyc tap --no-cov --timeout=300 --jobs=4 test/*.js test/reporters/*.js",
45+
"lint": "xo && (cd test/fixture && xo '**' '!{source-map-initial,syntax-error}.js' '!snapshots/test-sourcemaps/build/**')",
46+
"test": "npm run lint && flow check test/flow-types && tsc -p test/ts-types && nyc tap --no-cov --timeout=300 --jobs=4 test/*.js test/reporters/*.js",
4647
"test-win": "tap --no-cov --reporter=classic --timeout=300 --jobs=4 test/*.js test/reporters/*.js",
4748
"visual": "node test/visual/run-visual-tests.js",
4849
"prepublish": "npm run make-ts",

test/api.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function generateTests(prefix, apiCreator) {
340340
runStatus.on('error', data => {
341341
t.match(data.message, /Thrown by source-map-fixtures/);
342342
t.match(data.stack, /^.*?Object\.t.*?as run\b.*source-map-fixtures.src.throws.js:1.*$/m);
343-
t.match(data.stack, /^.*?Immediate\b.*source-map-file.js:12.*$/m);
343+
t.match(data.stack, /^.*?Immediate\b.*source-map-file.js:4.*$/m);
344344
});
345345
});
346346

@@ -361,7 +361,7 @@ function generateTests(prefix, apiCreator) {
361361
runStatus.on('error', data => {
362362
t.match(data.message, /Thrown by source-map-fixtures/);
363363
t.match(data.stack, /^.*?Object\.t.*?as run\b.*source-map-fixtures.src.throws.js:1.*$/m);
364-
t.match(data.stack, /^.*?Immediate\b.*source-map-file-browser-env.js:15.*$/m);
364+
t.match(data.stack, /^.*?Immediate\b.*source-map-file-browser-env.js:7.*$/m);
365365
});
366366
});
367367

@@ -382,7 +382,7 @@ function generateTests(prefix, apiCreator) {
382382
runStatus.on('error', data => {
383383
t.match(data.message, /Thrown by source-map-fixtures/);
384384
t.match(data.stack, /^.*?Object\.t.*?as run\b.*source-map-fixtures.src.throws.js:1.*$/m);
385-
t.match(data.stack, /^.*?Immediate\b.*source-map-file.js:12.*$/m);
385+
t.match(data.stack, /^.*?Immediate\b.*source-map-file.js:4.*$/m);
386386
});
387387
});
388388

test/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const test = require('tap').test;
99
const assert = require('../lib/assert');
1010
const snapshotManager = require('../lib/snapshot-manager');
1111
const Test = require('../lib/test');
12-
const HelloMessage = require('./fixture/HelloMessage');
12+
const HelloMessage = require('./fixture/hello-message');
1313

1414
let lastFailure = null;
1515
let lastPassed = false;

test/fixture/async-await.js

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

3-
test('async function', async function (t) {
3+
test('async function', async t => {
44
t.plan(1);
55
const value = await Promise.resolve(1);
66
t.is(value, 1);
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// empty
1+
// Empty

test/fixture/babel-hook.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import x from './babel-hook-imported';
1+
import './babel-hook-imported'; // eslint-disable-line import/no-unassigned-import

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = babel => {
1010
return {
1111
visitor: {
1212
CallExpression: path => {
13-
// skip require calls
14-
var firstArg = path.get('arguments')[0];
13+
// Skip require calls
14+
const firstArg = path.get('arguments')[0];
1515

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = babel => {
1010
return {
1111
visitor: {
1212
CallExpression: path => {
13-
// skip require calls
13+
// Skip require calls
1414
const firstArg = path.get('arguments')[0];
1515

1616
if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && !/repeated test/.test(firstArg.node.value)) {

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
This is used by some integration tests to validate correct handling of Babel config options.
1313
*/
1414

15+
/* eslint-disable new-cap */
1516
module.exports = babel => {
1617
const t = babel.types;
17-
const anonCount = 1;
18+
let anonCount = 1;
1819

1920
return {
2021
visitor: {
@@ -27,7 +28,7 @@ module.exports = babel => {
2728
if (args.length === 1) {
2829
args = [t.StringLiteral(`repeated test: anonymous${anonCount++}`), args[0]];
2930
} else if (args.length === 2 && args[0].type === 'StringLiteral') {
30-
if (/^repeated test/.test(args[0].value)) {
31+
if (args[0].value.startsWith('repeated test')) {
3132
return;
3233
}
3334

test/fixture/babelrc/test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import test from '../../../';
33
const fixture = [1, 2];
44

55
test('foo', t => {
6-
// using destructuring to ensure it transpiles on Node.js 4
6+
// Using destructuring to ensure it transpiles on Node.js 4
77
// since that is a Node.js 6 feature
88
const [one, two] = fixture;
9-
t.pass();
9+
t.is(one, 1);
10+
t.is(two, 2);
1011
});

test/fixture/es2015-source-maps.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixture/formatting.js

+31-32
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
2-
import renderer from 'react-test-renderer';
32
import {Buffer} from 'safe-buffer';
4-
import HelloMessage from './HelloMessage'
53
import test from '../../';
4+
import HelloMessage from './hello-message';
65

76
// Older AVA versions that do not use Concordance don't handle globals very
87
// well. Use this so formatting output can be contrasted between versions.
9-
const formatGlobals = !!require(process.env.AVA_PATH + '/package.json').dependencies.concordance
8+
const formatGlobals = Boolean(require(process.env.AVA_PATH + '/package.json').dependencies.concordance);
109

1110
test('date formatted', t => {
1211
const date = new Date('1969-07-20T20:17:40.000Z');
@@ -39,23 +38,23 @@ test('error formatted, constructor does not match name', t => {
3938
t.true(err);
4039
});
4140
test('error formatted, constructor does not match name, and string tag does not match constructor', t => {
42-
class Custom extends Error {
41+
class CustomError extends Error {
4342
constructor(message) {
4443
super(message);
45-
this.name = 'FamousWords';
44+
this.name = 'FamousWords'; // eslint-disable-line unicorn/custom-error-definition
4645
}
4746
}
48-
const err = new Custom('Houston, we have a problem');
47+
const err = new CustomError('Houston, we have a problem');
4948
t.true(err);
5049
});
5150
test('error formatted, no name or constructor', t => {
52-
class Custom extends Error {
51+
class CustomError extends Error {
5352
constructor(message) {
5453
super(message);
55-
this.name = '';
54+
this.name = ''; // eslint-disable-line unicorn/custom-error-definition
5655
}
5756
}
58-
const err = new Custom('Houston, we have a problem');
57+
const err = new CustomError('Houston, we have a problem');
5958
Object.defineProperty(err, 'constructor', {});
6059
t.true(err);
6160
});
@@ -70,7 +69,7 @@ test('error diff, extra properties', t => {
7069
date: new Date('1969-07-20T20:17:40.000Z')
7170
}));
7271
});
73-
test('error thrown in test', t => {
72+
test('error thrown in test', () => {
7473
throw Object.assign(new Error('Houston, we have a problem'), {
7574
date: new Date('1969-07-20T20:17:40.000Z')
7675
});
@@ -88,7 +87,7 @@ test('error thrown in test due to improper throws', t => {
8887
};
8988
t.throws(improper());
9089
});
91-
test('test returned rejected promise', t => {
90+
test('test returned rejected promise', () => {
9291
return Promise.reject(Object.assign(new Error('Houston, we have a problem'), {
9392
date: new Date('1969-07-20T20:17:40.000Z')
9493
}));
@@ -130,7 +129,7 @@ test('map diff, extra properties', t => {
130129
});
131130

132131
test('function formatted', t => {
133-
const fn = function foo() {};
132+
const fn = function foo() {}; // eslint-disable-line func-name-matching, func-names
134133
t.true(fn);
135134
});
136135
test('function diff', t => {
@@ -147,7 +146,7 @@ test('anonymous function', t => {
147146
t.true(() => {});
148147
});
149148
test('generator function', t => {
150-
t.true(function * foo() {});
149+
t.true(function * foo() {}); // eslint-disable-line func-names
151150
});
152151

153152
test('arguments formatted', t => {
@@ -289,25 +288,25 @@ test('circular references', t => {
289288
});
290289

291290
test('react element, formatted', t => {
292-
const element = React.createElement(HelloMessage, {name: 'Sindre'})
293-
t.true(element)
294-
})
291+
const element = React.createElement(HelloMessage, {name: 'Sindre'});
292+
t.true(element);
293+
});
295294
test('react element, complex attributes, formatted', t => {
296295
const element = React.createElement('div', {
297296
multiline: 'Hello\nworld',
298297
object: {foo: ['bar']}
299-
})
300-
t.true(element)
301-
})
298+
});
299+
t.true(element);
300+
});
302301
test('react element, opaque children, formatted', t => {
303-
const element = React.createElement('Foo', null, new Set(['foo']), true)
304-
t.true(element)
305-
})
302+
const element = React.createElement('Foo', null, new Set(['foo']), true);
303+
t.true(element);
304+
});
306305
test('react element, diff', t => {
307-
const element = React.createElement(HelloMessage, {name: 'Sindre'})
308-
const other = React.createElement(HelloMessage, {name: 'Vadim'})
309-
t.deepEqual(element, other)
310-
})
306+
const element = React.createElement(HelloMessage, {name: 'Sindre'});
307+
const other = React.createElement(HelloMessage, {name: 'Vadim'});
308+
t.deepEqual(element, other);
309+
});
311310

312311
test('deep structure, formatted', t => {
313312
const deep = {
@@ -318,9 +317,9 @@ test('deep structure, formatted', t => {
318317
}
319318
}
320319
}
321-
}
322-
t.true(deep)
323-
})
320+
};
321+
t.true(deep);
322+
});
324323
test('deep structure, diff', t => {
325324
const deep = {
326325
foo: {
@@ -330,6 +329,6 @@ test('deep structure, diff', t => {
330329
}
331330
}
332331
}
333-
}
334-
t.deepEqual(deep, Object.assign({corge: 'grault'}, deep))
335-
})
332+
};
333+
t.deepEqual(deep, Object.assign({corge: 'grault'}, deep));
334+
});
File renamed without changes.

test/fixture/immediate-0-exit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
'use strict';
2-
process.exit(0);
2+
process.exit(0); // eslint-disable-line unicorn/no-process-exit

test/fixture/immediate-3-exit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
'use strict';
2-
process.exit(3);
2+
process.exit(3); // eslint-disable-line unicorn/no-process-exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const Bluebird = require('bluebird'); // eslint-disable-line import/no-extraneous-dependencies
3+
4+
Bluebird.longStackTraces();
5+
module.exports = Bluebird;

test/fixture/long-stack-trace/enable-trace.js

-6
This file was deleted.

test/fixture/long-stack-trace/test.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import test from '../../../';
2-
import Promise from './enable-trace';
3-
2+
import Bluebird from './_enable-trace';
43

54
// This promise throwing pattern was used in bluebird documentation for long stack traces
65
// http://bluebirdjs.com/docs/api/promise.longstacktraces.html
76
test(async t => {
8-
const resolve = await Promise.resolve().then(function outer() {
9-
return Promise.resolve().then(function inner() {
10-
return Promise.resolve().then(function evenMoreInner() {
11-
a.b.c.d()
12-
}).catch(function catcher(e) {
13-
throw e.stack
14-
});
15-
});
16-
});
7+
await Bluebird.resolve().then(() => {
8+
return Bluebird.resolve().then(() => {
9+
return Bluebird.resolve().then(() => {
10+
a.b.c.d(); // eslint-disable-line no-undef
11+
});
12+
});
13+
}).catch(err => console.error(err.stack));
14+
t.fail();
1715
});

test/fixture/no-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import test from '../../';
1+
import '../../'; // eslint-disable-line import/no-unassigned-import

test/fixture/node-paths.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import foo from 'nested/foo';
2-
import bar from 'path/bar';
1+
import foo from 'nested/foo'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
2+
import bar from 'path/bar'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
33
import test from '../../';
44

55
test('relative require', t => {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import test from '../../../..'
1+
import test from '../../../..';
22

3-
test(() => {})
3+
test(() => {});

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'path';
21
import test from '../../../../';
32

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

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

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

3-
// this should never be loaded - package.json overrides files to call `actual.js`
3+
// This should never be loaded - package.json overrides files to call `actual.js`
44

55
test(t => {
66
t.fail();

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

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

3-
// this should never be loaded - package.json overrides files to call `actual.js`
3+
// This should never be loaded - package.json overrides files to call `actual.js`
44

55
test(t => {
66
t.fail();

0 commit comments

Comments
 (0)