Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8cf06e3

Browse files
committedSep 17, 2019
fix: add jest-runner-eslint fork + some updates
Signed-off-by: Charlike Mike Reagent <[email protected]>
1 parent 8a967fe commit 8cf06e3

File tree

18 files changed

+2054
-121
lines changed

18 files changed

+2054
-121
lines changed
 

‎.eslintignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
11
CHANGELOG.md
22
*.d.ts
3+
koa-better-body
4+
5+
*.tsbuildinfo
6+
.cache
7+
.*cache
8+
*.cache
9+
10+
# Build environment
11+
dist
12+
13+
# Package managers lockfiles
14+
package-lock.json
15+
shrinkwrap.json
16+
pnpm-lock.json
17+
18+
# Logs
19+
logs
20+
*.log
21+
*~
22+
23+
# Runtime data
24+
pids
25+
*.pid
26+
*.seed
27+
*.pid.lock
28+
29+
# Directory for instrumented libs generated by jscoverage/JSCover
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
coverage
34+
35+
# nyc test coverage
36+
.nyc_output
37+
38+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
39+
.grunt
40+
41+
# Bower dependency directory (https://bower.io/)
42+
bower_components
43+
44+
# node-waf configuration
45+
.lock-wscript
46+
47+
# Compiled binary addons (https://nodejs.org/api/addons.html)
48+
build/Release
49+
50+
# Dependency directories
51+
node_modules/
52+
jspm_packages/
53+
54+
# TypeScript v1 declaration files
55+
typings/
56+
57+
# Optional npm cache directory
58+
.npm
59+
60+
# Optional eslint cache
61+
.eslintcache
62+
63+
# Optional REPL history
64+
.node_repl_history
65+
66+
# Output of 'npm pack'
67+
*.tgz
68+
69+
# Yarn Integrity file
70+
.yarn-integrity
71+
72+
# dotenv environment variables file
73+
.env
74+
75+
# next.js build output
76+
.next

‎.eslintrc.js

Lines changed: 411 additions & 0 deletions
Large diffs are not rendered by default.

‎.jest-runnerrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
eslint: {},
3+
babel: {
4+
comments: false,
5+
},
6+
monorepo: true,
7+
};

‎@tunnckocore/.gitkeep

Whitespace-only changes.

‎@tunnckocore/execa/__tests__/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import execa, { exec, shell } from '../src/index';
1+
import execa, { exec, shell } from '../src';
22

33
test('default export execa v2 and named {shell, exec}', () => {
44
expect(typeof execa).toBe('function');

‎@tunnckocore/execa/src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ import pMap from 'p-map';
3838
*/
3939
export async function exec(cmds, options) {
4040
const commands = [].concat(cmds).filter(Boolean);
41-
const { concurrency = Infinity, ...opts } = Object.assign(
42-
{ preferLocal: true },
43-
options,
44-
);
41+
const { concurrency = Infinity, ...opts } = {
42+
preferLocal: true,
43+
...options,
44+
};
4545

4646
return pMap(commands, (cmd) => execa.command(cmd, opts), { concurrency });
4747
}
@@ -92,7 +92,7 @@ export async function exec(cmds, options) {
9292
* @public
9393
*/
9494
export function shell(cmds, options) {
95-
return exec(cmds, Object.assign({}, options, { shell: true }));
95+
return exec(cmds, { ...options, shell: true });
9696
}
9797

9898
/**
@@ -112,4 +112,4 @@ export function shell(cmds, options) {
112112
* @name execa
113113
* @public
114114
*/
115-
export default execa;
115+
export default execa;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const runner = require('../src/index');
22

3-
test('get extensions and workspaces - no workspaces', () => {
3+
test('todo', () => {
44
expect(typeof runner).toStrictEqual('function');
55
});

‎@tunnckocore/jest-runner-babel/src/runner.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,18 @@ const { pass, fail } = require('create-jest-runner');
55
const babel = require('@babel/core');
66
const cosmiconfig = require('cosmiconfig');
77

8-
const explorer = cosmiconfig('jest-runner-babel');
8+
const explorer = cosmiconfig('jest-runner');
99

1010
const isWin32 = os.platform() === 'win32';
1111

1212
module.exports = async ({ testPath, config }) => {
1313
const start = new Date();
14-
const cfg = explorer.searchSync();
15-
const runnerConfig = Object.assign(
16-
{ monorepo: false, outDir: 'dist', srcDir: 'src' },
17-
cfg.config,
18-
);
19-
20-
runnerConfig.isMonorepo =
21-
typeof runnerConfig.isMonorepo === 'function'
22-
? runnerConfig.isMonorepo
23-
: () => runnerConfig.monorepo;
14+
const options = normalizeRunnerConfig(explorer.searchSync());
2415

2516
let result = null;
2617

2718
try {
28-
result = babel.transformFileSync(testPath, runnerConfig.babel);
19+
result = babel.transformFileSync(testPath, options.babel);
2920
} catch (err) {
3021
return fail({
3122
start,
@@ -48,17 +39,7 @@ module.exports = async ({ testPath, config }) => {
4839
});
4940
}
5041

51-
runnerConfig.outDir = runnerConfig.outDir || runnerConfig.outdir;
52-
53-
if (typeof runnerConfig.outDir !== 'string') {
54-
runnerConfig.outDir = 'dist';
55-
}
56-
if (typeof runnerConfig.srcDir !== 'string') {
57-
runnerConfig.srcDir = 'src';
58-
}
59-
60-
let { rootDir } = config;
61-
let relativeTestPath = path.relative(rootDir, testPath);
42+
let relativeTestPath = path.relative(config.rootDir, testPath);
6243

6344
if (isWin32 && !relativeTestPath.includes('/')) {
6445
relativeTestPath = relativeTestPath.replace(/\\/g, '/');
@@ -72,44 +53,69 @@ module.exports = async ({ testPath, config }) => {
7253
// [ 'packages', 'foo', 'src', 'some', 'index.js' ]
7354
// so usually need to get the first 2 items
7455

75-
const segments = relativeTestPath.split('/');
76-
7756
// if not in monorepo, the `outs.dir` will be empty
78-
const outs = segments.reduce(
57+
const outs = relativeTestPath.split('/').reduce(
7958
(acc, item, index) => {
8059
// only if we are in monorepo we want to get the first 2 items
81-
if (runnerConfig.isMonorepo(config.cwd) && index < 2) {
60+
if (options.isMonorepo(config.cwd) && index < 2) {
8261
return { ...acc, dir: acc.dir.concat(item) };
8362
}
8463

8564
return {
8665
...acc,
8766
file: acc.file
88-
.concat(item === runnerConfig.srcDir ? null : item)
67+
.concat(item === options.srcDir ? null : item)
8968
.filter(Boolean),
9069
};
9170
},
9271
{ file: [], dir: [] },
9372
);
9473

9574
let outFile = path.join(
96-
rootDir,
75+
config.rootDir,
9776
...outs.dir.filter(Boolean),
98-
runnerConfig.outDir,
77+
options.outDir,
9978
...outs.file.filter(Boolean),
10079
);
10180

102-
const filename = path.basename(outFile, path.extname(outFile));
103-
10481
const outDir = path.dirname(outFile);
105-
outFile = path.join(outDir, `${filename}.js`);
82+
outFile = path.join(
83+
outDir,
84+
`${path.basename(outFile, path.extname(outFile))}.js`,
85+
);
10686

10787
fs.mkdirSync(outDir, { recursive: true });
10888
fs.writeFileSync(outFile, result.code);
10989

11090
return pass({
11191
start,
11292
end: new Date(),
113-
test: { path: outFile },
93+
test: { path: outFile, title: 'Babel' },
11494
});
11595
};
96+
97+
function normalizeRunnerConfig(val) {
98+
const cfg = val && val.config ? val.config : {};
99+
const runnerConfig = {
100+
monorepo: false,
101+
outDir: 'dist',
102+
srcDir: 'src',
103+
...cfg,
104+
};
105+
106+
runnerConfig.outDir = runnerConfig.outDir || runnerConfig.outdir;
107+
108+
if (typeof runnerConfig.outDir !== 'string') {
109+
runnerConfig.outDir = 'dist';
110+
}
111+
if (typeof runnerConfig.srcDir !== 'string') {
112+
runnerConfig.srcDir = 'src';
113+
}
114+
115+
runnerConfig.isMonorepo =
116+
typeof runnerConfig.isMonorepo === 'function'
117+
? runnerConfig.isMonorepo
118+
: () => runnerConfig.monorepo;
119+
120+
return runnerConfig;
121+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const runner = require('../src/index');
2+
3+
test('todo', () => {
4+
expect(typeof runner).toStrictEqual('function');
5+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"version": "0.1.0",
3+
"name": "@tunnckocore/jest-runner-eslint",
4+
"description": "WIP",
5+
"author": "Charlike Mike Reagent <opensource@tunnckocore.com>",
6+
"homepage": "https://github.com/tunnckoCore/opensource",
7+
"license": "MPL-2.0",
8+
"licenseStart": 2019,
9+
"main": "dist/main/index.js",
10+
"module": "dist/module/index.js",
11+
"types": "dist/types/index.d.ts",
12+
"scripts": {},
13+
"publishConfig": {
14+
"access": "public",
15+
"tag": "latest"
16+
},
17+
"engines": {
18+
"node": ">=8.11"
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/tunnckoCore/opensource.git",
23+
"directory": "@tunnckocore/jest-runner-eslint"
24+
},
25+
"dependencies": {
26+
"@tunnckocore/utils": "^0.4.1",
27+
"eslint": "^6.4.0",
28+
"cosmiconfig": "^5.2.1",
29+
"create-jest-runner": "^0.5.3"
30+
},
31+
"devDependencies": {},
32+
"peerDependencies": {},
33+
"files": [
34+
"dist"
35+
],
36+
"keywords": [
37+
"tunnckocorehq",
38+
"develop",
39+
"parallel",
40+
"series",
41+
"concurrency",
42+
"sequence",
43+
"exec",
44+
"child",
45+
"process",
46+
"execute",
47+
"fork",
48+
"execfile",
49+
"execa",
50+
"spawn",
51+
"file",
52+
"shell",
53+
"bin",
54+
"binary",
55+
"binaries",
56+
"npm",
57+
"path",
58+
"local"
59+
]
60+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createJestRunner } = require('create-jest-runner');
2+
3+
module.exports = createJestRunner(require.resolve('./runner'));
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// const os = require('os');
2+
// const path = require('path');
3+
const Module = require('module');
4+
5+
const { pass, fail, skip } = require('create-jest-runner');
6+
7+
// const utils = require('@tunnckocore/utils');
8+
const cosmiconfig = require('cosmiconfig');
9+
const { CLIEngine } = require('eslint');
10+
11+
// const DEFAULT_IGNORE = [
12+
// '**/node_modules/**',
13+
// '**/bower_components/**',
14+
// 'flow-typed/**',
15+
// 'coverage/**',
16+
// '{tmp,temp}/**',
17+
// '**/*.min.js',
18+
// '**/bundle.js',
19+
// 'vendor/**',
20+
// 'dist/**',
21+
// ];
22+
23+
// const DEFAULT_EXTENSIONS = ['js', 'jsx', 'mjs', 'ts', 'tsx'];
24+
25+
const explorer = cosmiconfig('jest-runner');
26+
27+
// function normalizeOptions(options) {
28+
// const result = explorer.searchSync(options.rootDir);
29+
// const opts = Object.assign(
30+
// {
31+
// exit: true,
32+
// warnings: false,
33+
// reporter: 'codeframe',
34+
// input: DEFAULT_INPUTS,
35+
// ignore: DEFAULT_IGNORE,
36+
// extensions: DEFAULT_EXTENSIONS,
37+
// },
38+
// options,
39+
// result && result.config,
40+
// {
41+
// fix: true,
42+
// cache: true,
43+
// cacheLocation: path.join(os.homedir() || os.tmpdir(), '.xaxa-cache'),
44+
// reportUnusedDisableDirectives: true,
45+
// useEslintrc: false,
46+
// baseConfig: {
47+
// extends: ['@tunnckocore'],
48+
// },
49+
// },
50+
// );
51+
52+
// const flat = (...args) => [].concat(...args).filter(Boolean);
53+
// opts.input = flat(opts.input);
54+
// opts.ignore = DEFAULT_IGNORE.concat(flat(opts.ignore));
55+
// opts.extensions = flat(opts.extensions);
56+
57+
// return opts;
58+
// }
59+
60+
module.exports = async ({ testPath }) => {
61+
const start = Date.now();
62+
const options = normalizeOptions(explorer.searchSync());
63+
64+
// if (config.setupTestFrameworkScriptFile) {
65+
// // eslint-disable-next-line import/no-dynamic-require,global-require
66+
// require(config.setupTestFrameworkScriptFile);
67+
// }
68+
// const opts = normalizeOptions({ ...extraOptions, rootDir: config.rootDir });
69+
70+
const engine = new CLIEngine(options.eslint);
71+
72+
if (engine.isPathIgnored(testPath)) {
73+
const end = Date.now();
74+
return skip({
75+
start,
76+
end,
77+
test: {
78+
path: testPath,
79+
title: 'ESLint',
80+
},
81+
});
82+
}
83+
84+
const report = engine.executeOnFiles([testPath]);
85+
86+
if (options.eslint.fix && !options.fixDryRun) {
87+
CLIEngine.outputFixes(report);
88+
}
89+
90+
const end = Date.now();
91+
const message = engine.getFormatter(options.reporter)(
92+
options.quiet ? CLIEngine.getErrorResults(report.results) : report.results,
93+
);
94+
95+
if (report.errorCount > 0) {
96+
return fail({
97+
start,
98+
end,
99+
test: {
100+
path: testPath,
101+
title: 'ESLint',
102+
errorMessage: message,
103+
},
104+
});
105+
}
106+
107+
const tooManyWarnings =
108+
options.maxWarnings >= 0 && report.warningCount > options.maxWarnings;
109+
110+
if (tooManyWarnings) {
111+
return fail({
112+
start,
113+
end,
114+
test: {
115+
path: testPath,
116+
title: 'ESLint',
117+
errorMessage: `${message}\nESLint found too many warnings (maximum: ${options.maxWarnings}).`,
118+
},
119+
});
120+
}
121+
122+
const result = pass({
123+
start,
124+
end,
125+
test: {
126+
path: testPath,
127+
title: 'ESLint',
128+
},
129+
});
130+
131+
if (!options.quiet && report.warningCount > 0) {
132+
result.console = [
133+
{
134+
message,
135+
origin: '',
136+
type: 'warn',
137+
},
138+
];
139+
}
140+
141+
return result;
142+
};
143+
144+
function normalizeOptions(val) {
145+
const cfg = val && val.config ? val.config : {};
146+
const eslintOptions = {
147+
// ignore: DEFAULT_IGNORE,
148+
exit: true,
149+
warnings: false,
150+
maxWarnings: 10,
151+
reporter: 'codeframe',
152+
// eslint-disable-next-line no-underscore-dangle
153+
extensions: Object.keys(Module._extensions),
154+
fix: true,
155+
reportUnusedDisableDirectives: true,
156+
...cfg.eslint,
157+
cache: true,
158+
// useEslintrc: false,
159+
// baseConfig: {
160+
// extends: ['@tunnckocore'],
161+
// },
162+
};
163+
164+
return {
165+
...cfg,
166+
eslint: eslintOptions,
167+
};
168+
}

‎@tunnckocore/utils/__tests__/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ test('createAliases return correct aliases', () => {
4141
const cwd = path.join(__dirname, 'fixtures', 'yarn-workspaces');
4242
const result = createAliases(cwd);
4343

44+
// eslint-disable-next-line unicorn/consistent-function-scoping
4445
const toAliases = (src) =>
4546
['@hela/foo', '@tunnckocore/bar'].reduce((acc, name) => {
4647
acc[name] = path.join(cwd, name, src);

‎@tunnckocore/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"homepage": "https://github.com/tunnckoCore/opensource",
77
"license": "MPL-2.0",
88
"licenseStart": 2019,
9-
"main": "dist/main/index.js",
9+
"main": "src/index.js",
1010
"module": "dist/module/index.js",
1111
"types": "dist/types/index.d.ts",
1212
"scripts": {},

‎jest.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
projects: [
3+
{
4+
displayName: 'lint',
5+
rootDir: __dirname,
6+
testMatch: [
7+
'<rootDir>/packages/*/src/**/*',
8+
'<rootDir>/@tunnckocore/*/src/**/*',
9+
],
10+
testPathIgnorePatterns: [
11+
/node_modules/.toString(),
12+
/.+\/fixtures\/.+/.toString(),
13+
],
14+
runner: './@tunnckocore/jest-runner-eslint/src/index.js',
15+
},
16+
{
17+
displayName: 'build',
18+
rootDir: __dirname,
19+
testMatch: [
20+
// '<rootDir>/packages/*/src/**/*',
21+
'<rootDir>/@tunnckocore/*/src/**/*',
22+
],
23+
testPathIgnorePatterns: [
24+
/node_modules/.toString(),
25+
/.+\/fixtures\/.+/.toString(),
26+
],
27+
runner: './@tunnckocore/jest-runner-babel/src/index.js',
28+
},
29+
],
30+
};

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
"@tunnckocore/prettier-config": "^0.2.2",
1818
"@tunnckocore/typescript-config": "^0.3.1",
1919
"eslint": "^6.4.0",
20+
"jest": "^24.9.0",
2021
"lerna": "^3.16.4",
2122
"prettier": "^1.18.2",
2223
"typescript": "^3.6.3"
2324
},
2425
"prettier": "@tunnckocore/prettier-config",
2526
"eslintConfig": {
26-
"extends": "@tunnckocore/eslint-config"
27+
"extends": "@tunnckocore"
2728
},
2829
"commitlint": {
2930
"extends": [

‎packages/.gitkeep

Whitespace-only changes.

‎yarn.lock

Lines changed: 1244 additions & 77 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.