-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.ts
More file actions
128 lines (115 loc) · 3.38 KB
/
index.ts
File metadata and controls
128 lines (115 loc) · 3.38 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import path from "path";
import fs from "fs";
import { minimatch } from "minimatch";
import {
FIXTURES_DIRECTORY,
PROJECT_DIRECTORY,
ddn,
IS_CLOUD_TEST_ENABLED,
setupDDNCLI,
login,
clear_project_dir,
pathToFileURL,
type GlobalConfig,
type FailedFixture,
} from "./utils";
clear_project_dir();
await setupDDNCLI();
await login();
await run_fixtures();
async function run_fixtures(
fixturesDir: string = FIXTURES_DIRECTORY,
): Promise<void> {
let selectorPattern: string = "*";
if (process.env.SELECTOR_PATTERN) {
selectorPattern = process.env.SELECTOR_PATTERN;
}
const entries = fs.readdirSync(fixturesDir, { withFileTypes: true });
const globalConfig: GlobalConfig = {};
const directories = entries
.filter((entry) => entry.isDirectory())
.map((dir) => dir.name);
const failedFixtures: FailedFixture[] = [];
const successfulFixtures: string[] = [];
for (const dir of directories) {
if (minimatch(dir, selectorPattern)) {
clear_project_dir();
let module: TestModule;
try {
module = await import(
pathToFileURL(path.join(fixturesDir, dir, "index.ts"))
);
} catch (e) {
console.error(`Error importing fixture ${dir}: ${e}. Trying JS module`);
try {
module = await import(
pathToFileURL(path.join(fixturesDir, dir, "index.js"))
);
} catch (e) {
console.error(`Error importing fixture ${dir}: ${e}`);
continue;
}
}
try {
console.log(`Setting up fixture "${dir}"`);
await module.setup(PROJECT_DIRECTORY, ddn(), globalConfig);
console.log(`Testing fixture "${dir}" in local`);
await module.test_local(path.join(fixturesDir, dir), globalConfig);
if (IS_CLOUD_TEST_ENABLED && module.test_cloud) {
console.log(`Testing fixture ${dir} in cloud`);
try {
await module.test_cloud(
PROJECT_DIRECTORY,
ddn(),
path.join(fixturesDir, dir),
globalConfig,
);
} catch (err) {
console.error(`Error testing fixture ${dir} in cloud: ${err}`);
failedFixtures.push({
name: dir,
error: err,
isCloud: true,
});
}
}
successfulFixtures.push(dir);
} catch (e) {
console.error(`Error testing fixture ${dir}: ${e}`);
failedFixtures.push({
name: dir,
error: e,
});
} finally {
try {
await module.teardown(PROJECT_DIRECTORY, globalConfig);
} catch (err) {
console.error(`Error tearing down fixture ${dir}: ${err}`);
}
clear_project_dir();
}
}
}
if (successfulFixtures.length > 0) {
console.log("Successful fixtures: ", successfulFixtures);
}
if (failedFixtures.length > 0) {
console.log("Failed fixtures: ", failedFixtures);
throw new Error(`One or more tests failed`);
}
}
interface TestModule {
setup: (
projectDir: string,
ddnCmd: string,
config: GlobalConfig,
) => Promise<void>;
test_local: (fixtureDir: string, config: GlobalConfig) => Promise<void>;
test_cloud?: (
projectDir: string,
ddnCmd: string,
fixtureDir: string,
config: GlobalConfig,
) => Promise<void>;
teardown: (projectDir: string, config: GlobalConfig) => Promise<void>;
}