Skip to content

Commit 52b6f48

Browse files
authored
Cli v3 e2e: fixtures (#1184)
* Run tests * Remove useless comments * Fix readme * Add fixtures for config step * Add fixture for additionalDependencies name parsing scope issue * Add URL to commit fix * Some fixtures will only use 1 package manager * Add resolve-trigger-deps fixture * use rimraf in test setup * Add legacy-peer-deps fixture * Use vitest fixtures * Add nested peer dep locking issue * Add missing peer dep resolving fixture * Get rid of global namespace, fix parallelism * Add console logs to debug log level * Add changeset * Remove comments * Update README.md
1 parent d22a460 commit 52b6f48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+12679
-421
lines changed

.changeset/polite-pots-walk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Add e2e fixtures corresponding to past issues
6+
Implement e2e suite parallelism
7+
Enhance log level for specific e2e suite messages

packages/cli-v3/e2e/README.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ This will test your fixture project, and generate outputs in the `packages/cli-v
9292

9393
This is necessary to allow to use `yarn` without having a warning on the current project being a `pnpm` project.
9494

95-
5. Install the fixture dependencies and generate lockfiles.
95+
5. Add the following `.yarnrc.yaml` in your fixture folder.
96+
97+
This will avoid having `.pnp.cjs` and `.pnp.loader.mjs` and keep versioned files to a minimum.
98+
99+
```yaml .yarnrc.yml
100+
nodeLinker: node-modules
101+
```
102+
103+
6. Install the fixture dependencies and generate lockfiles.
96104

97105
Like you would in any project.
98106
E.g. if your fixture contains a trigger task that uses the `jsdom` library:
@@ -105,19 +113,19 @@ This will test your fixture project, and generate outputs in the `packages/cli-v
105113

106114
> This will update the `package.json` and generate the `pnpm-lock.yaml` file.
107115

108-
6. To run the test suite against multiple package manager, we need to generate the other lockfiles.
116+
7. To run the test suite against multiple package manager, we need to generate the other lockfiles.
109117

110118
```sh
111119
cd packages/cli-v3/e2e/fixtures/<fixture-name>
112120
rm -rf node_modules
113121
npm install
114122
rm -rf node_modules
115-
corepack use yarn # will update the yarn lockfile
123+
corepack use yarn@4.2.2 # will update the yarn lockfile
116124
```
117125

118126
> Do it in this order, otherwise `npm install` will update the existing `yarn.lock` file with legacy version 1.
119127

120-
7. Create a new `packages/cli-v3/e2e/fixtures/trigger` folder, and create a trigger task in it.
128+
8. Create a new `packages/cli-v3/e2e/fixtures/trigger` folder, and create a trigger task in it.
121129

122130
Here is an example:
123131

@@ -132,7 +140,7 @@ This will test your fixture project, and generate outputs in the `packages/cli-v
132140
});
133141
```
134142

135-
8. Add a trigger configuration file.
143+
9. Add a trigger configuration file.
136144

137145
The configuration file is mandatory here, the E2E suite does not execute `trigger.dev` commands.
138146

@@ -145,33 +153,18 @@ This will test your fixture project, and generate outputs in the `packages/cli-v
145153

146154
> The project reference can be anything here, as the suite runs locally without connecting to the platform.
147155

148-
9. Commit your changes.
156+
10. Commit your changes.
149157

150-
10. Add your fixture test configuration in `testCases.json`.
158+
11. Add your fixture test configuration in `fixtures.config.js`.
151159

152-
```json testCases.json
153-
[
154-
...
160+
```javascript fixtures.config.js
161+
export const fixturesConfig = [
162+
// ...
155163
{
156-
"name": "<fixture-name>",
164+
id: "<fixture-name>",
157165
},
158-
...
159-
]
160-
```
161-
162-
You can configure your test case by adding other properties to the JSON object. Here is the `TestCase` type for reference:
163-
164-
```typescript
165-
type TestCase = {
166-
name: string;
167-
skipTypecheck?: boolean;
168-
wantConfigNotFoundError?: boolean;
169-
wantBadConfigError?: boolean;
170-
wantCompilationError?: boolean;
171-
wantWorkerError?: boolean;
172-
wantDependenciesError?: boolean;
173-
wantInstallationError?: boolean;
174-
};
166+
// ...
167+
];
175168
```
176169

177-
> You might expect a specific error at a specific test, so use those configuration option at your discretion.
170+
> You might expect a specific error for a specific test, so use those configuration option at your discretion.

packages/cli-v3/e2e/compile.ts

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,9 @@ export async function compile(options: CompileOptions) {
3333
} = options;
3434
const configPath =
3535
options.resolvedConfig.status === "file" ? options.resolvedConfig.path : undefined;
36-
37-
// COPIED FROM compileProject()
38-
// const compileSpinner = spinner();
39-
// compileSpinner.start(`Building project in ${config.projectDir}`);
40-
4136
const taskFiles = await gatherTaskFiles(config);
42-
const workerFacade = readFileSync(
43-
resolve("./dist/workers/prod/worker-facade.js"),
44-
// join(cliRootPath(), "workers", "prod", "worker-facade.js"),
45-
"utf-8"
46-
);
37+
const workerFacade = readFileSync(resolve("./dist/workers/prod/worker-facade.js"), "utf-8");
4738

48-
// const workerSetupPath = join(cliRootPath(), "workers", "prod", "worker-setup.js");
4939
const workerSetupPath = resolve("./dist/workers/prod/worker-setup.js");
5040

5141
let workerContents = workerFacade
@@ -74,7 +64,6 @@ export async function compile(options: CompileOptions) {
7464
const result = await build({
7565
stdin: {
7666
contents: workerContents,
77-
// resolveDir: process.cwd(),
7867
resolveDir: config.projectDir,
7968
sourcefile: "__entryPoint.ts",
8069
},
@@ -87,11 +76,7 @@ export async function compile(options: CompileOptions) {
8776
platform: "node",
8877
format: "cjs", // This is needed to support opentelemetry instrumentation that uses module patching
8978
target: ["node18", "es2020"],
90-
// outdir: "out",
9179
outdir: resolve(config.projectDir, "out"),
92-
// banner: {
93-
// js: `process.on("uncaughtException", function(error, origin) { if (error instanceof Error) { process.send && process.send({ type: "EVENT", message: { type: "UNCAUGHT_EXCEPTION", payload: { error: { name: error.name, message: error.message, stack: error.stack }, origin }, version: "v1" } }); } else { process.send && process.send({ type: "EVENT", message: { type: "UNCAUGHT_EXCEPTION", payload: { error: { name: "Error", message: typeof error === "string" ? error : JSON.stringify(error) }, origin }, version: "v1" } }); } });`,
94-
// },
9580
footer: {
9681
js: "process.exit();",
9782
},
@@ -112,31 +97,18 @@ export async function compile(options: CompileOptions) {
11297
});
11398

11499
if (result.errors.length > 0) {
115-
// compileSpinner.stop("Build failed, aborting deployment");
116-
117-
// span.setAttributes({
118-
// "build.workerErrors": result.errors.map(
119-
// (error) => `Error: ${error.text} at ${error.location?.file}`
120-
// ),
121-
// });
122-
123100
throw new Error("Build failed, aborting deployment");
124101
}
125102

126103
if (options.outputMetafile) {
127104
await writeJSONFile(join(options.outputMetafile, "worker.json"), result.metafile);
128105
}
129106

130-
const entryPointContents = readFileSync(
131-
resolve("./dist/workers/prod/entry-point.js"),
132-
// join(cliRootPath(), "workers", "prod", "entry-point.js"),
133-
"utf-8"
134-
);
107+
const entryPointContents = readFileSync(resolve("./dist/workers/prod/entry-point.js"), "utf-8");
135108

136109
const entryPointResult = await build({
137110
stdin: {
138111
contents: entryPointContents,
139-
// resolveDir: process.cwd(),
140112
resolveDir: config.projectDir,
141113
sourcefile: "index.ts",
142114
},
@@ -150,7 +122,6 @@ export async function compile(options: CompileOptions) {
150122
packages: "external",
151123
format: "cjs", // This is needed to support opentelemetry instrumentation that uses module patching
152124
target: ["node18", "es2020"],
153-
// outdir: "out",
154125
outdir: resolve(config.projectDir, "out"),
155126
define: {
156127
__PROJECT_CONFIG__: JSON.stringify(config),
@@ -161,14 +132,6 @@ export async function compile(options: CompileOptions) {
161132
});
162133

163134
if (entryPointResult.errors.length > 0) {
164-
// compileSpinner.stop("Build failed, aborting deployment");
165-
166-
// span.setAttributes({
167-
// "build.entryPointErrors": entryPointResult.errors.map(
168-
// (error) => `Error: ${error.text} at ${error.location?.file}`
169-
// ),
170-
// });
171-
172135
throw new Error("Build failed, aborting deployment");
173136
}
174137

@@ -179,13 +142,9 @@ export async function compile(options: CompileOptions) {
179142
);
180143
}
181144

182-
// Create a tmp directory to store the build
183-
// const tempDir = await createTempDir();
184-
185145
logger.debug(`Writing compiled files to ${tempDir}`);
186146

187147
// Get the metaOutput for the result build
188-
// const metaOutput = result.metafile!.outputs[posix.join("out", "stdin.js")];
189148
const metaOutput =
190149
result.metafile!.outputs[
191150
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")
@@ -194,8 +153,6 @@ export async function compile(options: CompileOptions) {
194153
invariant(metaOutput, "Meta output for the result build is missing");
195154

196155
// Get the metaOutput for the entryPoint build
197-
// const entryPointMetaOutput =
198-
// entryPointResult.metafile!.outputs[posix.join("out", "stdin.js")];
199156
const entryPointMetaOutput =
200157
entryPointResult.metafile!.outputs[
201158
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")

packages/cli-v3/e2e/createDeployHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type CreateDeployHashOptions = {
88
};
99

1010
export async function createDeployHash(options: CreateDeployHashOptions) {
11-
const { entryPointOutputFile, workerOutputFile } = options;
11+
const { dependencies, entryPointOutputFile, workerOutputFile } = options;
1212

1313
// COPIED FROM compileProject()
1414
const contentHasher = createHash("sha256");
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export interface TestCase {
2+
resolveEnv?: { [key: string]: string };
3+
id: string;
4+
skipTypecheck?: boolean;
5+
wantConfigNotFoundError?: boolean;
6+
wantConfigInvalidError?: boolean;
7+
wantCompilationError?: boolean;
8+
wantWorkerError?: boolean;
9+
wantDependenciesError?: boolean;
10+
wantInstallationError?: boolean;
11+
}
12+
13+
export const fixturesConfig: TestCase[] = [
14+
{
15+
id: "config-invalid",
16+
wantConfigInvalidError: true,
17+
},
18+
{
19+
id: "config-not-found",
20+
wantConfigNotFoundError: true,
21+
},
22+
{
23+
id: "dep-to-add-scope-parsing",
24+
skipTypecheck: true,
25+
},
26+
{
27+
id: "infisical-sdk",
28+
skipTypecheck: true,
29+
// Should not fail
30+
wantCompilationError: true,
31+
},
32+
{
33+
id: "lock-nested-peer-deps",
34+
skipTypecheck: true,
35+
resolveEnv: {
36+
npm_config_legacy_peer_deps: "true",
37+
},
38+
},
39+
{
40+
id: "resolve-legacy-peer-deps",
41+
skipTypecheck: true,
42+
// Should fail with better error at resolve
43+
wantWorkerError: true,
44+
},
45+
{
46+
id: "resolve-trigger-deps",
47+
skipTypecheck: true,
48+
},
49+
{
50+
id: "server-only",
51+
skipTypecheck: true,
52+
},
53+
{
54+
id: "trigger-dir-missing",
55+
skipTypecheck: true,
56+
},
57+
{
58+
id: "trigger-dir-not-found",
59+
skipTypecheck: true,
60+
// Should fail way before
61+
wantCompilationError: true,
62+
},
63+
];

packages/cli-v3/e2e/fixtures/no-config/package-lock.json renamed to packages/cli-v3/e2e/fixtures/config-invalid/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-v3/e2e/fixtures/no-config/package.json renamed to packages/cli-v3/e2e/fixtures/config-invalid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "no-config",
2+
"name": "config-invalid",
33
"private": true,
44
"packageManager": "[email protected]+sha256.4b4efa12490e5055d59b9b9fc9438b7d581a6b7af3b5675eb5c5f447cee1a589",
55
"engines": {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const config = {
2+
// 'project' field is mandatory
3+
triggerDirectories: [],
4+
};

packages/cli-v3/e2e/fixtures/no-config/yarn.lock renamed to packages/cli-v3/e2e/fixtures/config-invalid/yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ __metadata:
55
version: 8
66
cacheKey: 10c0
77

8-
"no-config@workspace:.":
8+
"config-invalid@workspace:.":
99
version: 0.0.0-use.local
10-
resolution: "no-config@workspace:."
10+
resolution: "config-invalid@workspace:."
1111
languageName: unknown
1212
linkType: soft
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

packages/cli-v3/e2e/fixtures/config-not-found/package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "config-not-found",
3+
"private": true,
4+
"packageManager": "[email protected]+sha256.4b4efa12490e5055d59b9b9fc9438b7d581a6b7af3b5675eb5c5f447cee1a589",
5+
"engines": {
6+
"pnpm": "8.15.5",
7+
"yarn": "4.2.2"
8+
}
9+
}

packages/cli-v3/e2e/fixtures/config-not-found/pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# https://github.com/pnpm/pnpm/issues/2412
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 8
6+
cacheKey: 10c0
7+
8+
"config-not-found@workspace:.":
9+
version: 0.0.0-use.local
10+
resolution: "config-not-found@workspace:."
11+
languageName: unknown
12+
linkType: soft

0 commit comments

Comments
 (0)