Skip to content

Commit

Permalink
fix: window e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Aug 21, 2024
1 parent 8b9378e commit a74da14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion scripts/mako.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path');
const fs = require('fs');
const { build } = require('@umijs/mako');
const cwd = process.argv[2];
const cwd = process.argv[2] || process.cwd();

console.log('> run mako build for', cwd);
const config = getMakoConfig();
Expand Down
29 changes: 8 additions & 21 deletions scripts/test-e2e.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import test from 'node:test';
import 'zx/globals';

function winPath(path) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
if (isExtendedLengthPath) {
return path;
}

return path.replace(/\\/g, '/');
}

function winJoin(...args) {
return winPath(path.join(...args));
}

// node version 小于 20 时退出
const nodeVersion = process.versions.node.split('.')[0];
if (nodeVersion < 20) {
Expand All @@ -22,25 +9,25 @@ if (nodeVersion < 20) {
}

const root = process.cwd();
const fixtures = winJoin(root, argv.fixtures || 'e2e/fixtures');
const fixtures = path.join(root, argv.fixtures || 'e2e/fixtures');
let onlyDir = argv.only ? argv.only : null;
const dirs = fs.readdirSync(fixtures).filter((dir) => {
if (dir.endsWith('-only')) {
onlyDir = dir;
}
return (
!dir.startsWith('.') &&
fs.statSync(winJoin(fixtures, dir)).isDirectory() &&
fs.existsSync(winJoin(fixtures, dir, 'expect.js'))
fs.statSync(path.join(fixtures, dir)).isDirectory() &&
fs.existsSync(path.join(fixtures, dir, 'expect.js'))
);
});

for (const dir of onlyDir ? [onlyDir] : dirs) {
const testFn = dir.includes('failed') && !argv.only ? test.skip : test;
await testFn(dir, async () => {
const cwd = winJoin(fixtures, dir);
const cwd = path.join(fixtures, dir);
if (argv.umi) {
if (!fs.existsSync(winJoin(cwd, 'node_modules'))) {
if (!fs.existsSync(path.join(cwd, 'node_modules'))) {
await $`cd ${cwd} && mkdir node_modules`;
}
// run umi build
Expand All @@ -53,11 +40,11 @@ for (const dir of onlyDir ? [onlyDir] : dirs) {
} else {
try {
// run mako build
await $`node ${winJoin(root, 'scripts', 'mako.js')} ${cwd}`;
await $`node ./mako.js`;
} catch (e) {
const isErrorCase = dir.split('.').includes('error');
if (isErrorCase) {
const mod = await import(winJoin(fixtures, dir, 'expect.js'));
const mod = await import(path.join(fixtures, dir, 'expect.js'));
mod.default(e);
return;
} else {
Expand All @@ -66,7 +53,7 @@ for (const dir of onlyDir ? [onlyDir] : dirs) {
}
}
// run expect.js
const mod = await import(winJoin(fixtures, dir, 'expect.js'));
const mod = await import(path.join(fixtures, dir, 'expect.js'));
if (mod && typeof mod.default === 'function') {
await mod.default();
}
Expand Down

0 comments on commit a74da14

Please sign in to comment.