Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions napi/oxlint/test/__snapshots__/e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Found 3 warnings and 3 errors.
Finished in Xms on 1 file using X threads."
`;

exports[`oxlint CLI > should lint a directory with errors 1`] = `
exports[`oxlint CLI > should lint a directory with errors with JS plugins enabled 1`] = `
"
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed
,-[index.js:1:1]
Expand All @@ -68,7 +68,25 @@ Found 0 warnings and 1 error.
Finished in Xms on 1 file using X threads."
`;

exports[`oxlint CLI > should lint a directory without errors 1`] = `
exports[`oxlint CLI > should lint a directory with errors without JS plugins enabled 1`] = `
"
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed
,-[index.js:1:1]
1 | debugger;
: ^^^^^^^^^
\`----
help: Remove the debugger statement

Found 0 warnings and 1 error.
Finished in Xms on 1 file using X threads."
`;

exports[`oxlint CLI > should lint a directory without errors with JS plugins enabled 1`] = `
"Found 0 warnings and 0 errors.
Finished in Xms on 1 file using X threads."
`;

exports[`oxlint CLI > should lint a directory without errors without JS plugins enabled 1`] = `
"Found 0 warnings and 0 errors.
Finished in Xms on 1 file using X threads."
`;
Expand Down
24 changes: 20 additions & 4 deletions napi/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,43 @@ import { execa } from 'execa';
const PACKAGE_ROOT_PATH = path.dirname(import.meta.dirname);
const ENTRY_POINT_PATH = path.join(PACKAGE_ROOT_PATH, 'dist/index.js');

async function runOxlint(cwd: string, args: string[] = []) {
return await execa('node', [ENTRY_POINT_PATH, '--experimental-js-plugins', ...args], {
async function runOxlintWithoutPlugins(cwd: string, args: string[] = []) {
return await execa('node', [ENTRY_POINT_PATH, ...args], {
cwd: path.join(PACKAGE_ROOT_PATH, cwd),
reject: false,
});
}

async function runOxlint(cwd: string, args: string[] = []) {
return await runOxlintWithoutPlugins(cwd, ['--experimental-js-plugins', ...args]);
}

function normalizeOutput(output: string): string {
return output
.replace(/Finished in \d+(\.\d+)?(s|ms|us|ns)/, 'Finished in Xms')
.replace(/using \d+ threads./, 'using X threads.');
}

describe('oxlint CLI', () => {
it('should lint a directory without errors', async () => {
it('should lint a directory without errors without JS plugins enabled', async () => {
const { stdout, exitCode } = await runOxlintWithoutPlugins('test/fixtures/built_in_no_errors');
expect(exitCode).toBe(0);
expect(normalizeOutput(stdout)).toMatchSnapshot();
});

it('should lint a directory with errors without JS plugins enabled', async () => {
const { stdout, exitCode } = await runOxlintWithoutPlugins('test/fixtures/built_in_errors');
expect(exitCode).toBe(1);
expect(normalizeOutput(stdout)).toMatchSnapshot();
});

it('should lint a directory without errors with JS plugins enabled', async () => {
const { stdout, exitCode } = await runOxlint('test/fixtures/built_in_no_errors');
expect(exitCode).toBe(0);
expect(normalizeOutput(stdout)).toMatchSnapshot();
});

it('should lint a directory with errors', async () => {
it('should lint a directory with errors with JS plugins enabled', async () => {
const { stdout, exitCode } = await runOxlint('test/fixtures/built_in_errors');
expect(exitCode).toBe(1);
expect(normalizeOutput(stdout)).toMatchSnapshot();
Expand Down
Loading