forked from vercel/turborepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the ESLint caching. (vercel#2859)
I pulled the trigger too fast on vercel#2850, these are the tests that should have been written for it.
- Loading branch information
1 parent
6006545
commit fb5229f
Showing
12 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import JSON5 from "json5"; | ||
import { execSync } from "child_process"; | ||
|
||
describe("eslint settings check", () => { | ||
beforeAll(() => { | ||
const cwd = path.join(__dirname, "fixtures", "workspace"); | ||
execSync(`npm install`, { cwd }); | ||
}); | ||
|
||
afterAll(() => { | ||
const nodeModulesDir = path.join( | ||
__dirname, | ||
"fixtures", | ||
"workspace", | ||
"node_modules" | ||
); | ||
fs.rmSync(nodeModulesDir, { force: true, recursive: true }); | ||
}); | ||
|
||
it("does the right thing for peers", () => { | ||
const cwd = path.join(__dirname, "fixtures", "workspace"); | ||
const configString = execSync(`eslint --print-config peer.js`, { | ||
cwd, | ||
encoding: "utf8", | ||
}); | ||
const configJson = JSON.parse(configString); | ||
|
||
expect(configJson.settings).toEqual({ | ||
turbo: { envVars: ["CI", "UNORDERED"] }, | ||
}); | ||
}); | ||
|
||
it("does the right thing for child dirs", () => { | ||
const cwd = path.join(__dirname, "fixtures", "workspace", "child"); | ||
const configString = execSync(`eslint --print-config child.js`, { | ||
cwd, | ||
encoding: "utf8", | ||
}); | ||
const configJson = JSON.parse(configString); | ||
|
||
expect(configJson.settings).toEqual({ | ||
turbo: { envVars: ["CI", "UNORDERED"] }, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("eslint cache is busted", () => { | ||
let turboJsonPath: string; | ||
let originalString: string; | ||
|
||
beforeAll(() => { | ||
const cwd = path.join(__dirname, "fixtures", "workspace"); | ||
execSync(`npm install`, { cwd }); | ||
|
||
turboJsonPath = path.join(__dirname, "fixtures", "workspace", "turbo.json"); | ||
originalString = fs.readFileSync(turboJsonPath, { encoding: "utf8" }); | ||
}); | ||
|
||
afterEach(() => { | ||
fs.writeFileSync(turboJsonPath, originalString); | ||
}); | ||
|
||
afterAll(() => { | ||
fs.writeFileSync(turboJsonPath, originalString); | ||
|
||
const nodeModulesDir = path.join( | ||
__dirname, | ||
"fixtures", | ||
"workspace", | ||
"node_modules" | ||
); | ||
fs.rmSync(nodeModulesDir, { force: true, recursive: true }); | ||
}); | ||
|
||
it("catches a lint error after changing config", () => { | ||
expect.assertions(2); | ||
|
||
// ensure that we populate the cache with a failure. | ||
const cwd = path.join(__dirname, "fixtures", "workspace", "child"); | ||
try { | ||
execSync(`eslint --format=json child.js`, { cwd, encoding: "utf8" }); | ||
} catch (error: any) { | ||
const outputJson = JSON.parse(error.stdout); | ||
expect(outputJson).toMatchObject([ | ||
{ | ||
messages: [ | ||
{ | ||
message: | ||
"$NONEXISTENT is not listed as a dependency in turbo.json", | ||
}, | ||
], | ||
}, | ||
]); | ||
} | ||
|
||
// change the configuration | ||
const turboJson = JSON5.parse(originalString); | ||
turboJson.globalEnv = ["CI", "NONEXISTENT"]; | ||
fs.writeFileSync(turboJsonPath, JSON.stringify(turboJson, null, 2)); | ||
|
||
// test that we invalidated the eslint cache | ||
const output = execSync(`eslint --format=json child.js`, { | ||
cwd, | ||
encoding: "utf8", | ||
}); | ||
const outputJson = JSON.parse(output); | ||
expect(outputJson).toMatchObject([{ errorCount: 0 }]); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/eslint-plugin-turbo/__tests__/fixtures/workspace/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["plugin:turbo/recommended"], | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/eslint-plugin-turbo/__tests__/fixtures/workspace/child/child.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
process.env.NONEXISTENT | ||
process.env.CI |
5 changes: 5 additions & 0 deletions
5
packages/eslint-plugin-turbo/__tests__/fixtures/workspace/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"eslint-plugin-turbo": "../../.." | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/eslint-plugin-turbo/__tests__/fixtures/workspace/peer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
process.env.CI |
1 change: 1 addition & 0 deletions
1
...tests__/lib/fixtures/workspace/turbo.json → ...o/__tests__/fixtures/workspace/turbo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters