2024-08-08 15:39:07 +08:00
|
|
|
import { randomUUID } from 'node:crypto';
|
|
|
|
import { existsSync, unlinkSync } from 'node:fs';
|
|
|
|
import { execa } from 'execa';
|
|
|
|
import { describe, expect, test, vi } from 'vitest';
|
|
|
|
|
|
|
|
const cliBin = require.resolve('../bin/midscene');
|
|
|
|
vi.setConfig({
|
|
|
|
testTimeout: 30 * 1000,
|
|
|
|
});
|
2024-09-09 18:07:22 +08:00
|
|
|
describe.skipIf(process.platform !== 'darwin')('bin', () => {
|
2024-08-08 15:39:07 +08:00
|
|
|
test('error order', async () => {
|
|
|
|
const params = [
|
|
|
|
'--query',
|
|
|
|
'{name: string, status: string}[], service status of github page',
|
|
|
|
'--url',
|
|
|
|
'https://www.baidu.com/',
|
|
|
|
];
|
|
|
|
expect(async () => {
|
|
|
|
await execa(cliBin, params);
|
|
|
|
}).rejects.toThrowError();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('basic action', async () => {
|
|
|
|
const randomFileName = `status-${randomUUID()}.json`;
|
|
|
|
const params = [
|
|
|
|
'--url',
|
|
|
|
'https://www.githubstatus.com/',
|
|
|
|
'--query-output',
|
|
|
|
randomFileName,
|
|
|
|
'--query',
|
|
|
|
'{name: string, status: string}[], service status of github page',
|
|
|
|
];
|
|
|
|
const { failed } = await execa(cliBin, params);
|
|
|
|
expect(failed).toBe(false);
|
|
|
|
|
|
|
|
expect(existsSync(randomFileName)).toBeTruthy();
|
|
|
|
unlinkSync(randomFileName);
|
|
|
|
});
|
2024-11-12 11:54:40 +08:00
|
|
|
|
|
|
|
test('serve', async () => {
|
|
|
|
const params = [
|
|
|
|
'--serve',
|
|
|
|
'./tests/server_root',
|
|
|
|
'--url',
|
|
|
|
'index.html',
|
|
|
|
'--assert',
|
|
|
|
'the content title is "My App"',
|
|
|
|
];
|
|
|
|
const { failed } = await execa(cliBin, params);
|
|
|
|
expect(failed).toBe(false);
|
|
|
|
});
|
2024-08-08 15:39:07 +08:00
|
|
|
});
|