Skip to content

Commit

Permalink
Lint test fixtures
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
novemberborn committed Oct 1, 2017
1 parent fa4f73c commit 8955e15
Show file tree
Hide file tree
Showing 60 changed files with 126 additions and 126 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -42,7 +42,8 @@
"node": ">=4"
},
"scripts": {
"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",
"lint": "xo && (cd test/fixture && xo '**' '!{source-map-initial,syntax-error}.js' '!snapshots/test-sourcemaps/build/**')",
"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",
"test-win": "tap --no-cov --reporter=classic --timeout=300 --jobs=4 test/*.js test/reporters/*.js",
"visual": "node test/visual/run-visual-tests.js",
"prepublish": "npm run make-ts",
Expand Down
6 changes: 3 additions & 3 deletions test/api.js
Expand Up @@ -340,7 +340,7 @@ function generateTests(prefix, apiCreator) {
runStatus.on('error', data => {
t.match(data.message, /Thrown by source-map-fixtures/);
t.match(data.stack, /^.*?Object\.t.*?as run\b.*source-map-fixtures.src.throws.js:1.*$/m);
t.match(data.stack, /^.*?Immediate\b.*source-map-file.js:12.*$/m);
t.match(data.stack, /^.*?Immediate\b.*source-map-file.js:4.*$/m);
});
});

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/assert.js
Expand Up @@ -9,7 +9,7 @@ const test = require('tap').test;
const assert = require('../lib/assert');
const snapshotManager = require('../lib/snapshot-manager');
const Test = require('../lib/test');
const HelloMessage = require('./fixture/HelloMessage');
const HelloMessage = require('./fixture/hello-message');

let lastFailure = null;
let lastPassed = false;
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/async-await.js
@@ -1,6 +1,6 @@
import test from '../../';

test('async function', async function (t) {
test('async function', async t => {
t.plan(1);
const value = await Promise.resolve(1);
t.is(value, 1);
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/ava-files/cwd/dir-a/test/bar.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/cwd/dir-a/test/foo.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/cwd/dir-b/test/baz.js
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/default-patterns/test-foo.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/default-patterns/test.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/default-patterns/test/_foo-help.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/default-patterns/test/baz.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/default-patterns/test/deep/deep.js
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/no-duplicates/lib/bar.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/ava-files/no-duplicates/lib/foo.js
@@ -1 +1 @@
// empty
// Empty
2 changes: 1 addition & 1 deletion test/fixture/babel-hook.js
@@ -1 +1 @@
import x from './babel-hook-imported';
import './babel-hook-imported'; // eslint-disable-line import/no-unassigned-import
4 changes: 2 additions & 2 deletions test/fixture/babel-plugin-foo-to-bar.js
Expand Up @@ -10,8 +10,8 @@ module.exports = babel => {
return {
visitor: {
CallExpression: path => {
// skip require calls
var firstArg = path.get('arguments')[0];
// Skip require calls
const 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')));
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/babel-plugin-test-capitalizer.js
Expand Up @@ -10,7 +10,7 @@ module.exports = babel => {
return {
visitor: {
CallExpression: path => {
// skip require calls
// Skip require calls
const firstArg = path.get('arguments')[0];

if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && !/repeated test/.test(firstArg.node.value)) {
Expand Down
5 changes: 3 additions & 2 deletions test/fixture/babel-plugin-test-doubler.js
Expand Up @@ -12,9 +12,10 @@
This is used by some integration tests to validate correct handling of Babel config options.
*/

/* eslint-disable new-cap */
module.exports = babel => {
const t = babel.types;
const anonCount = 1;
let anonCount = 1;

return {
visitor: {
Expand All @@ -27,7 +28,7 @@ module.exports = babel => {
if (args.length === 1) {
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)) {
if (args[0].value.startsWith('repeated test')) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions test/fixture/babelrc/test.js
Expand Up @@ -3,8 +3,9 @@ import test from '../../../';
const fixture = [1, 2];

test('foo', t => {
// using destructuring to ensure it transpiles on Node.js 4
// Using destructuring to ensure it transpiles on Node.js 4
// since that is a Node.js 6 feature
const [one, two] = fixture;
t.pass();
t.is(one, 1);
t.is(two, 2);
});
3 changes: 2 additions & 1 deletion test/fixture/es2015-source-maps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 31 additions & 32 deletions test/fixture/formatting.js
@@ -1,12 +1,11 @@
import React from 'react';
import renderer from 'react-test-renderer';
import {Buffer} from 'safe-buffer';
import HelloMessage from './HelloMessage'
import test from '../../';
import HelloMessage from './hello-message';

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

test('date formatted', t => {
const date = new Date('1969-07-20T20:17:40.000Z');
Expand Down Expand Up @@ -39,23 +38,23 @@ test('error formatted, constructor does not match name', t => {
t.true(err);
});
test('error formatted, constructor does not match name, and string tag does not match constructor', t => {
class Custom extends Error {
class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'FamousWords';
this.name = 'FamousWords'; // eslint-disable-line unicorn/custom-error-definition
}
}
const err = new Custom('Houston, we have a problem');
const err = new CustomError('Houston, we have a problem');
t.true(err);
});
test('error formatted, no name or constructor', t => {
class Custom extends Error {
class CustomError extends Error {
constructor(message) {
super(message);
this.name = '';
this.name = ''; // eslint-disable-line unicorn/custom-error-definition
}
}
const err = new Custom('Houston, we have a problem');
const err = new CustomError('Houston, we have a problem');
Object.defineProperty(err, 'constructor', {});
t.true(err);
});
Expand All @@ -70,7 +69,7 @@ test('error diff, extra properties', t => {
date: new Date('1969-07-20T20:17:40.000Z')
}));
});
test('error thrown in test', t => {
test('error thrown in test', () => {
throw Object.assign(new Error('Houston, we have a problem'), {
date: new Date('1969-07-20T20:17:40.000Z')
});
Expand All @@ -88,7 +87,7 @@ test('error thrown in test due to improper throws', t => {
};
t.throws(improper());
});
test('test returned rejected promise', t => {
test('test returned rejected promise', () => {
return Promise.reject(Object.assign(new Error('Houston, we have a problem'), {
date: new Date('1969-07-20T20:17:40.000Z')
}));
Expand Down Expand Up @@ -130,7 +129,7 @@ test('map diff, extra properties', t => {
});

test('function formatted', t => {
const fn = function foo() {};
const fn = function foo() {}; // eslint-disable-line func-name-matching, func-names
t.true(fn);
});
test('function diff', t => {
Expand All @@ -147,7 +146,7 @@ test('anonymous function', t => {
t.true(() => {});
});
test('generator function', t => {
t.true(function * foo() {});
t.true(function * foo() {}); // eslint-disable-line func-names
});

test('arguments formatted', t => {
Expand Down Expand Up @@ -289,25 +288,25 @@ test('circular references', t => {
});

test('react element, formatted', t => {
const element = React.createElement(HelloMessage, {name: 'Sindre'})
t.true(element)
})
const element = React.createElement(HelloMessage, {name: 'Sindre'});
t.true(element);
});
test('react element, complex attributes, formatted', t => {
const element = React.createElement('div', {
multiline: 'Hello\nworld',
object: {foo: ['bar']}
})
t.true(element)
})
});
t.true(element);
});
test('react element, opaque children, formatted', t => {
const element = React.createElement('Foo', null, new Set(['foo']), true)
t.true(element)
})
const element = React.createElement('Foo', null, new Set(['foo']), true);
t.true(element);
});
test('react element, diff', t => {
const element = React.createElement(HelloMessage, {name: 'Sindre'})
const other = React.createElement(HelloMessage, {name: 'Vadim'})
t.deepEqual(element, other)
})
const element = React.createElement(HelloMessage, {name: 'Sindre'});
const other = React.createElement(HelloMessage, {name: 'Vadim'});
t.deepEqual(element, other);
});

test('deep structure, formatted', t => {
const deep = {
Expand All @@ -318,9 +317,9 @@ test('deep structure, formatted', t => {
}
}
}
}
t.true(deep)
})
};
t.true(deep);
});
test('deep structure, diff', t => {
const deep = {
foo: {
Expand All @@ -330,6 +329,6 @@ test('deep structure, diff', t => {
}
}
}
}
t.deepEqual(deep, Object.assign({corge: 'grault'}, deep))
})
};
t.deepEqual(deep, Object.assign({corge: 'grault'}, deep));
});
File renamed without changes.
2 changes: 1 addition & 1 deletion test/fixture/immediate-0-exit.js
@@ -1,2 +1,2 @@
'use strict';
process.exit(0);
process.exit(0); // eslint-disable-line unicorn/no-process-exit
2 changes: 1 addition & 1 deletion test/fixture/immediate-3-exit.js
@@ -1,2 +1,2 @@
'use strict';
process.exit(3);
process.exit(3); // eslint-disable-line unicorn/no-process-exit
5 changes: 5 additions & 0 deletions test/fixture/long-stack-trace/_enable-trace.js
@@ -0,0 +1,5 @@
'use strict';
const Bluebird = require('bluebird'); // eslint-disable-line import/no-extraneous-dependencies

Bluebird.longStackTraces();
module.exports = Bluebird;
6 changes: 0 additions & 6 deletions test/fixture/long-stack-trace/enable-trace.js

This file was deleted.

20 changes: 9 additions & 11 deletions test/fixture/long-stack-trace/test.js
@@ -1,17 +1,15 @@
import test from '../../../';
import Promise from './enable-trace';

import Bluebird from './_enable-trace';

// This promise throwing pattern was used in bluebird documentation for long stack traces
// http://bluebirdjs.com/docs/api/promise.longstacktraces.html
test(async t => {
const resolve = await Promise.resolve().then(function outer() {
return Promise.resolve().then(function inner() {
return Promise.resolve().then(function evenMoreInner() {
a.b.c.d()
}).catch(function catcher(e) {
throw e.stack
});
});
});
await Bluebird.resolve().then(() => {
return Bluebird.resolve().then(() => {
return Bluebird.resolve().then(() => {
a.b.c.d(); // eslint-disable-line no-undef
});
});
}).catch(err => console.error(err.stack));
t.fail();
});
2 changes: 1 addition & 1 deletion test/fixture/no-tests.js
@@ -1 +1 @@
import test from '../../';
import '../../'; // eslint-disable-line import/no-unassigned-import
4 changes: 2 additions & 2 deletions test/fixture/node-paths.js
@@ -1,5 +1,5 @@
import foo from 'nested/foo';
import bar from 'path/bar';
import foo from 'nested/foo'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
import bar from 'path/bar'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved
import test from '../../';

test('relative require', t => {
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/pkg-conf/fail-without-assertions/test.js
@@ -1,3 +1,3 @@
import test from '../../../..'
import test from '../../../..';

test(() => {})
test(() => {});
1 change: 0 additions & 1 deletion test/fixture/pkg-conf/pkg-overrides/actual.js
@@ -1,4 +1,3 @@
import path from 'path';
import test from '../../../../';

const opts = JSON.parse(process.argv[2]);
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/pkg-overrides/test.js
@@ -1,6 +1,6 @@
import test from '../../../../';

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

test(t => {
t.fail();
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/precedence/a.js
@@ -1,6 +1,6 @@
import test from '../../../../';

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

test(t => {
t.fail();
Expand Down

0 comments on commit 8955e15

Please sign in to comment.