Skip to content

Commit c2d12df

Browse files
committed
feat(config/lintstaged): split lint + test tasks up in order to leverage parallelization
1 parent 326d632 commit c2d12df

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/config/helpers/build-lint-staged.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ const {resolveHoverScripts, resolveBin} = require('../../utils')
22

33
const hoverScripts = resolveHoverScripts()
44
const doctoc = resolveBin('doctoc')
5+
56
const defaultTestCommand = `${hoverScripts} test --findRelatedTests`
67

8+
const sourceExtensions = ['js', 'jsx', 'ts', 'tsx']
9+
10+
const readmeGlob = 'README.md'
11+
const formatGlob =
12+
'*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)'
13+
14+
// This works around the limitation imposed by using globs as keys in the
15+
// configuration. We want to run the lint and test commands on the same glob,
16+
// but we want to do so in parallel. If we specify the commands in an array
17+
// under the same glob key, they always run in sequence.
18+
const lintGlob = `*.+(${sourceExtensions.join('|')})`
19+
const testGlob = `*.+(${sourceExtensions.reverse().join('|')})`
20+
721
const buildConfig = (testCommand = defaultTestCommand) => ({
8-
'README.md': [`${doctoc} --maxlevel 4 --notitle`],
9-
'*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)': [
10-
`${hoverScripts} format`,
11-
],
12-
'*.+(js|jsx|ts|tsx)': [`${hoverScripts} lint`, testCommand],
22+
[readmeGlob]: [`${doctoc} --maxlevel 4 --notitle`],
23+
[formatGlob]: [`${hoverScripts} format`],
24+
[lintGlob]: [`${hoverScripts} lint`],
25+
[testGlob]: [testCommand],
1326
})
1427

1528
module.exports = {buildConfig}

src/scripts/__tests__/__snapshots__/pre-commit.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Array [
5858
exports[`pre-commit overrides built-in test command with --test-command 2`] = `
5959
Array [
6060
.test-tmp/hover-javascriptTMPSUFFIX/.lintstaged.json,
61-
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint","yarn test:custom --findRelatedTests foo.js"]},
61+
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint"],"*.+(tsx|ts|jsx|js)":["yarn test:custom --findRelatedTests foo.js"]},
6262
]
6363
`;
6464

@@ -72,7 +72,7 @@ Array [
7272
exports[`pre-commit overrides built-in test command with --test-command and forwards args 2`] = `
7373
Array [
7474
.test-tmp/hover-javascriptTMPSUFFIX/.lintstaged.json,
75-
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint","yarn test:custom --findRelatedTests foo.js"]},
75+
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint"],"*.+(tsx|ts|jsx|js)":["yarn test:custom --findRelatedTests foo.js"]},
7676
]
7777
`;
7878

@@ -86,7 +86,7 @@ Array [
8686
exports[`pre-commit overrides built-in test command with --testCommand 2`] = `
8787
Array [
8888
.test-tmp/hover-javascriptTMPSUFFIX/.lintstaged.json,
89-
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint","yarn test:custom --findRelatedTests foo.js"]},
89+
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint"],"*.+(tsx|ts|jsx|js)":["yarn test:custom --findRelatedTests foo.js"]},
9090
]
9191
`;
9292

@@ -100,7 +100,7 @@ Array [
100100
exports[`pre-commit overrides built-in test command with --testCommand and forwards args 2`] = `
101101
Array [
102102
.test-tmp/hover-javascriptTMPSUFFIX/.lintstaged.json,
103-
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint","yarn test:custom --findRelatedTests foo.js"]},
103+
{"README.md":["doctoc --maxlevel 4 --notitle"],"*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)":["./src/index.js format"],"*.+(js|jsx|ts|tsx)":["./src/index.js lint"],"*.+(tsx|ts|jsx|js)":["yarn test:custom --findRelatedTests foo.js"]},
104104
]
105105
`;
106106

0 commit comments

Comments
 (0)