Skip to content

Commit

Permalink
chore: eslint test (#524)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom <[email protected]>
  • Loading branch information
wangjinyang and Tom authored Apr 28, 2023
1 parent cc1b85f commit 62539c3
Showing 1 changed file with 4 additions and 60 deletions.
64 changes: 4 additions & 60 deletions test/e2e/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,14 @@
import { SpawnOptionsWithoutStdio } from 'child_process';
import { shuvi, resolveFixture } from '../utils';
import { shuviSync, resolveFixture } from '../utils';

jest.setTimeout(30 * 1000);

function createTestCtx(fixture: string) {
const projectRoot = resolveFixture(fixture);

const runCommand = (
command: string,
args: string[] = [],
options?: SpawnOptionsWithoutStdio
) => {
return new Promise<{ code: number; message: string }>((resolve, reject) => {
let output = '';
let err = '';
const s = shuvi(command, [projectRoot, ...args], {
...options
});

if (s.stdout === null || s.stderr === null) {
return reject({
code: -1,
message: `fail to run ${command}`
});
}

s.stdout.on('data', data => {
output += data;
});

s.stderr.on('data', data => {
err += data;
});

s.on('exit', code => {
if (code === 0) {
resolve({
code,
message: output
});
} else {
reject({
code,
message: err
});
}
});
});
};

return {
run: runCommand
};
}

describe('shuvi lint', () => {
let message = '';

beforeAll(async () => {
const project = createTestCtx('eslint');
try {
await project.run('lint');
} catch (error) {
console.log('error: ', error);
message = (error as { message: string }).message;
}
const projectRoot = resolveFixture('eslint');
const child_process = shuviSync('lint', [projectRoot]);
message = child_process.stderr.toString();
});

it('should tip no-html-link-for-pages', async () => {
Expand Down

0 comments on commit 62539c3

Please sign in to comment.