Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: precompile with babel #257

Merged
merged 1 commit into from May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
@@ -1 +1,2 @@
coverage/
lib/
4 changes: 3 additions & 1 deletion .eslintrc.js
@@ -1,6 +1,6 @@
'use strict';

const { globals } = require('./index').environments.globals;
const { globals } = require('./').environments.globals;

module.exports = {
extends: [
Expand Down Expand Up @@ -32,6 +32,8 @@ module.exports = {
},
],
'prettier/prettier': 'error',
'node/no-unsupported-features/es-syntax': 'off',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

babel deals with syntax

'node/no-unsupported-features/es-builtins': 'error',
},
overrides: [
{
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
node_modules/
coverage/
lib/
5 changes: 5 additions & 0 deletions babel.config.js
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
presets: [['@babel/preset-env', { targets: { node: 6 } }]],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Node 8 and next release major?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to make a breaking change, exactly 0 benefit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenever we wanna make a new major we can drop 6 though, no reason to keep it at that point

};
25 changes: 19 additions & 6 deletions package.json
Expand Up @@ -16,24 +16,31 @@
},
"files": [
"docs/",
"rules/",
"processors/",
"index.js"
"src/",
"lib/"
],
"main": "lib/",
"engines": {
"node": ">=6"
},
"peerDependencies": {
"eslint": ">=5"
},
"scripts": {
"postinstall": "yarn build",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is auto-build after install helpful in this case?
Unlike in the Jest repo, you'll be able to run yarn jest just fine.
In development, yarn build --watch will initially build everything anyway (afaik that's what Babel CLI watch does)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint will fail since we run with our own rules. And jest runs lint, so it'd fail

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, didn't consider that 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB postInstall runs when this package is being npm/yarn installed.

We can't assume that the user has yarn or any of the devDependencies.

I think we should revert it for now.

Copy link
Contributor

@ranyitz ranyitz May 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the intention was pretest? I've created #265

"lint": "eslint . --ignore-pattern '!.eslintrc.js'",
"prettylint": "prettylint docs/**/*.md README.md package.json",
"test": "jest"
"prepublishOnly": "yarn build",
"test": "jest",
"build": "babel src --out-dir lib"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"babel-jest": "^24.8.0",
"eslint": "^5.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-eslint-plugin": "^2.0.0",
Expand All @@ -49,7 +56,7 @@
"prettier": {
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "es5"
"trailingComma": "all"
},
"lint-staged": {
"*.js": [
Expand All @@ -73,13 +80,19 @@
"projects": [
{
"displayName": "test",
"testEnvironment": "node"
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
]
},
{
"displayName": "lint",
"runner": "jest-runner-eslint",
"testMatch": [
"<rootDir>/**/*.js"
],
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
]
}
]
Expand Down
8 changes: 4 additions & 4 deletions __tests__/rules.test.js → src/__tests__/rules.test.js
Expand Up @@ -2,19 +2,19 @@

const fs = require('fs');
const path = require('path');
const { rules } = require('../index');
const { rules } = require('../');

const ruleNames = Object.keys(rules);
const numberOfRules = 31;

describe('rules', () => {
it('should have a corresponding doc for each rule', () => {
ruleNames.forEach(rule => {
const docPath = path.resolve(__dirname, '../docs/rules', `${rule}.md`);
const docPath = path.resolve(__dirname, '../../docs/rules', `${rule}.md`);

if (!fs.existsSync(docPath)) {
throw new Error(
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
`Could not find documentation file for rule "${rule}" in path "${docPath}"`,
);
}
});
Expand All @@ -24,7 +24,7 @@ describe('rules', () => {
const { length } = ruleNames;
if (length !== numberOfRules) {
throw new Error(
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`,
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion index.js → src/index.js
Expand Up @@ -9,7 +9,7 @@ const rules = fs
.map(rule => path.basename(rule, '.js'))
.reduce(
(acc, curr) => Object.assign(acc, { [curr]: require(`./rules/${curr}`) }),
{}
{},
);

const snapshotProcessor = require('./processors/snapshot-processor');
Expand Down
Expand Up @@ -6,7 +6,7 @@ const preprocess = source => [source];
const postprocess = messages =>
messages[0].filter(
// snapshot files should only be linted with snapshot specific rules
message => message.ruleId === 'jest/no-large-snapshots'
message => message.ruleId === 'jest/no-large-snapshots',
);

module.exports = {
Expand Down
Expand Up @@ -285,7 +285,7 @@ ruleTester.run(
output: 'test("foo")',
},
],
}
},
);

ruleTester.run('consistent-test-it with fn=it and withinDescribe=it ', rule, {
Expand Down
File renamed without changes.
Expand Up @@ -23,10 +23,10 @@ ruleTester.run('no-identical-title', rule, {
['it("it1", function() {});', 'it("it2", function() {});'].join('\n'),
['it.only("it1", function() {});', 'it("it2", function() {});'].join('\n'),
['it.only("it1", function() {});', 'it.only("it2", function() {});'].join(
'\n'
'\n',
),
['describe("title", function() {});', 'it("title", function() {});'].join(
'\n'
'\n',
),
[
'describe("describe1", function() {',
Expand Down Expand Up @@ -136,7 +136,7 @@ ruleTester.run('no-identical-title', rule, {
},
{
code: ['it("it1", function() {});', 'it("it1", function() {});'].join(
'\n'
'\n',
),
errors: [
{
Expand All @@ -163,7 +163,7 @@ ruleTester.run('no-identical-title', rule, {
},
{
code: ['fit("it1", function() {});', 'it("it1", function() {});'].join(
'\n'
'\n',
),
errors: [
{
Expand Down
Expand Up @@ -15,21 +15,21 @@ ruleTester.run('no-large-snapshots', rule, {
{
filename: 'mock.js',
code: `expect(something).toMatchInlineSnapshot(\`\n${'line\n'.repeat(
2
2,
)}\`);`,
},
{
filename: 'mock.js',
code: `expect(something).toThrowErrorMatchingInlineSnapshot(\`\n${'line\n'.repeat(
2
2,
)}\`);`,
},
],
invalid: [
{
filename: 'mock.js',
code: `expect(something).toMatchInlineSnapshot(\`\n${'line\n'.repeat(
50
50,
)}\`);`,
errors: [
{
Expand All @@ -41,7 +41,7 @@ ruleTester.run('no-large-snapshots', rule, {
{
filename: 'mock.js',
code: `expect(something).toThrowErrorMatchingInlineSnapshot(\`\n${'line\n'.repeat(
50
50,
)}\`);`,
errors: [
{
Expand Down
Expand Up @@ -69,7 +69,7 @@ module.exports = {
nodeName.indexOf(testKeywordWithinDescribe) === -1
) {
const oppositeTestKeyword = getOppositeTestKeyword(
testKeywordWithinDescribe
testKeywordWithinDescribe,
);

context.report({
Expand All @@ -85,7 +85,7 @@ module.exports = {

const fixedNodeName = getPreferredNodeName(
nodeName,
testKeywordWithinDescribe
testKeywordWithinDescribe,
);
return [fixer.replaceText(nodeToReplace, fixedNodeName)];
},
Expand Down
4 changes: 2 additions & 2 deletions rules/expect-expect.js → src/rules/expect-expect.js
Expand Up @@ -30,7 +30,7 @@ module.exports = {
const assertFunctionNames = new Set(
context.options[0] && context.options[0].assertFunctionNames
? context.options[0].assertFunctionNames
: ['expect']
: ['expect'],
);

return {
Expand All @@ -54,7 +54,7 @@ module.exports = {
context.report({
message: 'Test has no assertions',
node,
})
}),
);
},
};
Expand Down
File renamed without changes.
Expand Up @@ -47,7 +47,7 @@ module.exports = {

// Check if the method used matches any of ours
const methodItem = methodNames.find(
item => item[1] === targetNode.name
item => item[1] === targetNode.name,
);

if (methodItem) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -75,7 +75,7 @@ module.exports = {
context,
currentLayer.describeTitles,
node,
title
title,
);
},
'CallExpression:exit'(node) {
Expand Down
Expand Up @@ -127,7 +127,7 @@ module.exports = {
return [
fixer.replaceText(
node.parent,
`jest.setTimeout(${node.parent.right.value})`
`jest.setTimeout(${node.parent.right.value})`,
),
];
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -19,7 +19,7 @@ module.exports = {
return [
fixer.replaceText(
node.callee.property,
'toMatchInlineSnapshot'
'toMatchInlineSnapshot',
),
];
},
Expand All @@ -32,7 +32,7 @@ module.exports = {
return [
fixer.replaceText(
node.callee.property,
'toThrowErrorMatchingInlineSnapshot'
'toThrowErrorMatchingInlineSnapshot',
),
];
},
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-spy-on.js → src/rules/prefer-spy-on.js
Expand Up @@ -54,11 +54,11 @@ module.exports = {
fixer.insertTextBefore(node.left, `jest.spyOn(`),
fixer.replaceTextRange(
[node.left.object.range[1], node.left.property.range[0]],
`, ${leftPropQuote}`
`, ${leftPropQuote}`,
),
fixer.replaceTextRange(
[node.left.property.range[1], jestFnCall.range[1]],
`${leftPropQuote})${mockImplementation}`
`${leftPropQuote})${mockImplementation}`,
),
];
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions rules/prefer-to-contain.js → src/rules/prefer-to-contain.js
Expand Up @@ -39,7 +39,7 @@ const getNegationFixes = (node, sourceCode, fixer) => {
const negationPropertyDot = sourceCode.getFirstTokenBetween(
node.parent.object,
node.parent.property,
token => token.value === '.'
token => token.value === '.',
);
const toContainFunc =
isEqualityNegation(node) && argument(node.parent).value
Expand All @@ -63,7 +63,7 @@ const getCommonFixes = (node, sourceCode, fixer) => {
const propertyDot = sourceCode.getFirstTokenBetween(
includesCaller.object,
includesCaller.property,
token => token.value === '.'
token => token.value === '.',
);

const closingParenthesis = sourceCode.getTokenAfter(containArg);
Expand Down Expand Up @@ -114,8 +114,8 @@ module.exports = {
fixArr.push(
fixer.replaceText(
argument(node),
sourceCode.getText(containArg)
)
sourceCode.getText(containArg),
),
);
return fixArr;
},
Expand Down
Expand Up @@ -35,7 +35,7 @@ module.exports = {
.getFirstTokenBetween(
node.arguments[0].object,
node.arguments[0].property,
token => token.value === '.'
token => token.value === '.',
);
context.report({
fix(fixer) {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rules/util.js → src/rules/util.js
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const { version } = require('../package.json');
const { version } = require('../../package.json');

const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest';

Expand Down
File renamed without changes.
Expand Up @@ -98,7 +98,7 @@ const verifyExpectWithReturn = (
promiseCallbacks,
node,
context,
testFunctionBody
testFunctionBody,
) => {
promiseCallbacks.some(promiseCallback => {
if (promiseCallback && isFunction(promiseCallback)) {
Expand Down Expand Up @@ -156,7 +156,7 @@ module.exports = {
[fulfillmentCallback, rejectionCallback],
node,
context,
testFunctionBody
testFunctionBody,
);
}
}
Expand Down
File renamed without changes.