Skip to content

Commit

Permalink
test: fix error, environment difference
Browse files Browse the repository at this point in the history
- `TextEncoder/TextDecoder` is a Node API
- `Uint8Array` is a jsdom API
  • Loading branch information
deot committed Sep 5, 2023
1 parent 4b03f92 commit 8b54e5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/builder/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'node:fs';
import { Locals, Shell } from '@deot/dev-shared';
import * as Builder from '@deot/dev-builder';

// @vitest-environment node
describe('index', () => {
it('config', () => {
const it = Locals.impl();
Expand Down
40 changes: 27 additions & 13 deletions packages/dever/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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();
Expand Down Expand Up @@ -36,24 +37,37 @@ describe('index', () => {

let expects = ['/components/button/index.html', '/vue/index.html', '/react/index.html'];
await new Promise<void>(resolve => {
const run = (url: string, timeout: number) => {
task = task
.then(() => {
return ctx.page.goto(url, { timeout });
})
.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((e) => {
if (e.toString().includes('TimeoutError')) {
console.log(url, /url/);
run(url, 10000);
} else {
console.log(e);
}
});
};
subprocess.stdout.on('data', (data) => {
data = data.toString().replace(/(\t|\n|\v|\r|\f|\s)/g, '');
if (!data) return;

data.split('>').forEach((url: string) => {
data.split('>').filter(i => !!i).forEach((url: string) => {
url = url.match(/(.*)(http:.*)/)?.[2] || '';
if (url && expects.some(i => url.includes(i))) {
task = task
.then(() => ctx.page.goto(url))
.then(() => 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);
run(url, 5000);
}
});
});
Expand Down

0 comments on commit 8b54e5b

Please sign in to comment.