-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
66 lines (60 loc) · 1.83 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* eslint-disable no-promise-executor-return */
import * as path from 'node:path';
import { Locals, Shell } from '@deot/dev-shared';
import * as Dever from '@deot/dev-dever';
import { Launch } from '@deot/dev-test';
// @vitest-environment node
describe('index', () => {
it('config', () => {
const it = Locals.impl();
expect(it.cwd).toMatch('/dev');
});
it('run', async () => {
expect(typeof Dever.run).toBe('function');
});
it('singlerepo', async () => {
expect.assertions(1);
const { stdout } = await Shell.exec(`npm`, ['run', 'dev'], {
cwd: path.resolve('./packages/_/singlerepo'),
stdio: 'pipe'
});
expect(stdout).toMatch('no entry file found!');
}, 60000);
it('monorepo', async () => {
expect.assertions(3);
const ctx = new Launch();
await ctx.createPage();
let task = Promise.resolve();
const subprocess = Shell.spawn(`npm`, ['run', 'dev'], {
cwd: path.resolve('./packages/_/monorepo'),
stdio: 'pipe'
});
let expects = ['/components/button/index.html', '/vue/index.html', '/react/index.html'];
await new Promise<void>(resolve => {
subprocess.stdout.on('data', (data) => {
data = data.toString().replace(/(\t|\n|\v|\r|\f|\s)/g, '');
if (!data) return;
data.split('>').filter(i => !!i).forEach((url: string) => {
url = url.match(/(.*)(http:.*)/)?.[2] || '';
if (url && expects.some(i => url.includes(i))) {
task = task
.then(() => {
return ctx.page.goto(url);
})
.then(() => {
return ctx.operater.html("#test");
})
.then((res) => {
expect(res).toMatch('Hello World!');
expects = expects.filter(i => !url.includes(i));
if (!expects.length) {
subprocess.kill();
ctx.browser.close().then(() => resolve());
}
}).catch(console.log);
}
});
});
});
}, 60000);
});