-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the first integration test (#124)
- Loading branch information
Showing
20 changed files
with
373 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'steiger': patch | ||
--- | ||
|
||
The diagnostics from a single rule are now sorted by path in alphabetical order |
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 @@ | ||
export const App = {} |
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 @@ | ||
export { App } from './App' |
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,3 @@ | ||
import { App } from '@/app/ui/App' | ||
|
||
console.log(App) |
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,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"jsx": "react-jsx", | ||
"moduleResolution": "Bundler", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["src/*"] | ||
} | ||
}, | ||
"include": ["src"] | ||
} |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
{} | ||
{ | ||
"files": [], | ||
"references": [{ "path": "./tsconfig.app.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,10 @@ | ||
# How to write integration tests | ||
|
||
> [!NOTE] | ||
> You should develop tests on either Mac or Linux. If you have a Windows machine, consider using a [devcontainer](containers.dev). | ||
> | ||
> This is mainly because the Unicode symbols used in the output are always replaced by fallbacks on Windows, so converting outputs from Windows to POSIX isn't practical. | ||
Create a new file with the `.test.ts` extension in the `tests/` folder. Use `tests/smoke.test.ts` as a reference on how to set up a temporary folder for the project and execute Steiger. | ||
|
||
Store your output snapshots in `__snapshots__` with the `-posix.txt` extension. After you wrote your test, run `pnpm update-windows-snapshots` to copy over the changes in snapshots. |
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 @@ | ||
export { default } from '@steiger/eslint-config' |
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,37 @@ | ||
{ | ||
"private": true, | ||
"name": "@steiger/integration-tests", | ||
"description": "Integration tests for Steiger", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"test": "vitest run", | ||
"update-windows-snapshots": "node ./scripts/update-windows-snapshots.mjs" | ||
}, | ||
"exports": { | ||
".": "./src/index.ts" | ||
}, | ||
"type": "module", | ||
"authors": [ | ||
{ | ||
"name": "Lev Chelyadinov", | ||
"email": "[email protected]", | ||
"url": "https://github.com/illright" | ||
} | ||
], | ||
"devDependencies": { | ||
"@steiger/eslint-config": "workspace:*", | ||
"@steiger/tsconfig": "workspace:*", | ||
"@total-typescript/ts-reset": "^0.6.1", | ||
"@types/node": "^18.11.9", | ||
"eslint": "^9.16.0", | ||
"figures": "^6.1.0", | ||
"get-bin-path": "^11.0.0", | ||
"prettier": "^3.4.2", | ||
"tinyexec": "^0.3.1", | ||
"typescript": "^5.7.2", | ||
"vitest": "^3.0.0-beta.2" | ||
}, | ||
"dependencies": { | ||
"steiger": "workspace:*" | ||
} | ||
} |
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 @@ | ||
// Do not add any other lines of code to this file! | ||
import '@total-typescript/ts-reset' |
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,23 @@ | ||
/** | ||
* Run this script on Mac or Linux when you update test snapshots to port these changes over to Windows snapshots. | ||
* | ||
* $ pnpm run update-windows-snapshots | ||
*/ | ||
|
||
import * as fs from 'node:fs/promises' | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { replaceSymbols } from 'figures' | ||
|
||
const snapshotsFolder = join(dirname(fileURLToPath(import.meta.url)), '../tests/__snapshots__') | ||
|
||
// Go through each POSIX snapshot and replace the forward slashes in diagnostic paths with backslashes | ||
for (const file of await fs.readdir(snapshotsFolder)) { | ||
if (file.endsWith('-posix.txt')) { | ||
const windowsSnapshotName = file.slice(0, -'-posix.txt'.length) + '-windows.txt' | ||
const updatedSnapshot = replaceSymbols(await fs.readFile(join(snapshotsFolder, file), 'utf8'), { | ||
useFallback: true, | ||
}).replace(/(?<=┌.+)\//gm, '\\') | ||
await fs.writeFile(join(snapshotsFolder, windowsSnapshotName), updatedSnapshot) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
integration-tests/tests/__snapshots__/smoke-stderr-posix.txt
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,45 @@ | ||
|
||
┌ src/entities/user/api/getUser.ts | ||
✘ Forbidden import from higher layer "app". | ||
│ | ||
└ fsd/forbidden-imports (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/forbidden-imports) | ||
|
||
┌ src/entities | ||
✘ Inconsistent pluralization of slice names. Prefer all plural names | ||
✔ Auto-fixable | ||
│ | ||
└ fsd/inconsistent-naming (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/inconsistent-naming) | ||
|
||
┌ src/entities/user | ||
✘ This slice has no references. Consider removing it. | ||
│ | ||
└ fsd/insignificant-slice (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/insignificant-slice) | ||
|
||
┌ src/entities/users | ||
✘ This slice has no references. Consider removing it. | ||
│ | ||
└ fsd/insignificant-slice (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/insignificant-slice) | ||
|
||
┌ src/entities/user/api/getUser.ts | ||
✘ Forbidden sidestep of public API when importing from "@/app/ui/App". | ||
│ | ||
└ fsd/no-public-api-sidestep (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-public-api-sidestep) | ||
|
||
┌ src/entities/user/ui/api | ||
✘ Having a folder with the name "api" inside a segment could be confusing because that name is commonly used for segments. Consider renaming it. | ||
│ | ||
└ fsd/no-reserved-folder-names (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-reserved-folder-names) | ||
|
||
┌ src/app/ui | ||
✘ Layer "app" should not have "ui" segment. | ||
│ | ||
└ fsd/no-ui-in-app (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-ui-in-app) | ||
|
||
┌ src/processes | ||
✘ Layer "processes" is deprecated, avoid using it | ||
│ | ||
└ fsd/no-processes (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-processes) | ||
|
||
──────────────────────────────────────────────────────── | ||
Found 8 errors (1 can be fixed automatically with --fix) | ||
|
45 changes: 45 additions & 0 deletions
45
integration-tests/tests/__snapshots__/smoke-stderr-windows.txt
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,45 @@ | ||
|
||
┌ src\entities\user\api\getUser.ts | ||
× Forbidden import from higher layer "app". | ||
│ | ||
└ fsd/forbidden-imports (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/forbidden-imports) | ||
|
||
┌ src\entities | ||
× Inconsistent pluralization of slice names. Prefer all plural names | ||
√ Auto-fixable | ||
│ | ||
└ fsd/inconsistent-naming (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/inconsistent-naming) | ||
|
||
┌ src\entities\user | ||
× This slice has no references. Consider removing it. | ||
│ | ||
└ fsd/insignificant-slice (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/insignificant-slice) | ||
|
||
┌ src\entities\users | ||
× This slice has no references. Consider removing it. | ||
│ | ||
└ fsd/insignificant-slice (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/insignificant-slice) | ||
|
||
┌ src\entities\user\api\getUser.ts | ||
× Forbidden sidestep of public API when importing from "@/app/ui/App". | ||
│ | ||
└ fsd/no-public-api-sidestep (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-public-api-sidestep) | ||
|
||
┌ src\entities\user\ui\api | ||
× Having a folder with the name "api" inside a segment could be confusing because that name is commonly used for segments. Consider renaming it. | ||
│ | ||
└ fsd/no-reserved-folder-names (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-reserved-folder-names) | ||
|
||
┌ src\app\ui | ||
× Layer "app" should not have "ui" segment. | ||
│ | ||
└ fsd/no-ui-in-app (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-ui-in-app) | ||
|
||
┌ src\processes | ||
× Layer "processes" is deprecated, avoid using it | ||
│ | ||
└ fsd/no-processes (https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-processes) | ||
|
||
──────────────────────────────────────────────────────── | ||
Found 8 errors (1 can be fixed automatically with --fix) | ||
|
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,24 @@ | ||
import * as fs from 'node:fs/promises' | ||
import os from 'node:os' | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { exec } from 'tinyexec' | ||
|
||
import { expect, test } from 'vitest' | ||
|
||
import { getSteigerBinPath } from '../utils/get-bin-path.js' | ||
|
||
const temporaryDirectory = await fs.realpath(os.tmpdir()) | ||
const steiger = await getSteigerBinPath() | ||
const kitchenSinkExample = join(dirname(fileURLToPath(import.meta.url)), '../../examples/kitchen-sink-of-fsd-issues') | ||
const pathPlatform = os.platform() === 'win32' ? 'windows' : 'posix' | ||
|
||
test('basic functionality in the kitchen sink example project', async () => { | ||
const project = join(temporaryDirectory, 'smoke') | ||
await fs.rm(project, { recursive: true, force: true }) | ||
await fs.cp(kitchenSinkExample, project, { recursive: true }) | ||
|
||
const { stderr } = await exec('node', [steiger, 'src'], { nodeOptions: { cwd: project, env: { NO_COLOR: '1' } } }) | ||
|
||
await expect(stderr).toMatchFileSnapshot(join('__snapshots__', `smoke-stderr-${pathPlatform}.txt`)) | ||
}) |
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,7 @@ | ||
{ | ||
"extends": "@steiger/tsconfig/base.json", | ||
"include": ["./tests", "./utils", "./scripts", "./reset.d.ts"], | ||
"compilerOptions": { | ||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.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,22 @@ | ||
import { promises as fs } from 'node:fs' | ||
import * as process from 'node:process' | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { getBinPath } from 'get-bin-path' | ||
|
||
/** | ||
* Resolve the full path to the built JS file of Steiger. | ||
* | ||
* Rejects if the file doesn't exist. | ||
*/ | ||
export async function getSteigerBinPath() { | ||
const steiger = (await getBinPath({ cwd: join(dirname(fileURLToPath(import.meta.url)), '../../packages/steiger') }))! | ||
try { | ||
await fs.stat(steiger) | ||
} catch { | ||
console.error('Run `turbo build` before running integration tests') | ||
process.exit(1) | ||
} | ||
|
||
return steiger | ||
} |
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
Oops, something went wrong.