Skip to content

Cli v3 e2e: fixtures #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/polite-pots-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"trigger.dev": patch
---

Add e2e fixtures corresponding to past issues
Implement e2e suite parallelism
Enhance log level for specific e2e suite messages
51 changes: 22 additions & 29 deletions packages/cli-v3/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ This will test your fixture project, and generate outputs in the `packages/cli-v

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

5. Install the fixture dependencies and generate lockfiles.
5. Add the following `.yarnrc.yaml` in your fixture folder.

This will avoid having `.pnp.cjs` and `.pnp.loader.mjs` and keep versioned files to a minimum.

```yaml .yarnrc.yml
nodeLinker: node-modules
```

6. Install the fixture dependencies and generate lockfiles.

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

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

6. To run the test suite against multiple package manager, we need to generate the other lockfiles.
7. To run the test suite against multiple package manager, we need to generate the other lockfiles.

```sh
cd packages/cli-v3/e2e/fixtures/<fixture-name>
rm -rf node_modules
npm install
rm -rf node_modules
corepack use yarn # will update the yarn lockfile
corepack use yarn@4.2.2 # will update the yarn lockfile
```

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

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

Here is an example:

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

8. Add a trigger configuration file.
9. Add a trigger configuration file.

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

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

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

9. Commit your changes.
10. Commit your changes.

10. Add your fixture test configuration in `testCases.json`.
11. Add your fixture test configuration in `fixtures.config.js`.

```json testCases.json
[
...
```javascript fixtures.config.js
export const fixturesConfig = [
// ...
{
"name": "<fixture-name>",
id: "<fixture-name>",
},
...
]
```

You can configure your test case by adding other properties to the JSON object. Here is the `TestCase` type for reference:

```typescript
type TestCase = {
name: string;
skipTypecheck?: boolean;
wantConfigNotFoundError?: boolean;
wantBadConfigError?: boolean;
wantCompilationError?: boolean;
wantWorkerError?: boolean;
wantDependenciesError?: boolean;
wantInstallationError?: boolean;
};
// ...
];
```

> You might expect a specific error at a specific test, so use those configuration option at your discretion.
> You might expect a specific error for a specific test, so use those configuration option at your discretion.
47 changes: 2 additions & 45 deletions packages/cli-v3/e2e/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,9 @@ export async function compile(options: CompileOptions) {
} = options;
const configPath =
options.resolvedConfig.status === "file" ? options.resolvedConfig.path : undefined;

// COPIED FROM compileProject()
// const compileSpinner = spinner();
// compileSpinner.start(`Building project in ${config.projectDir}`);

const taskFiles = await gatherTaskFiles(config);
const workerFacade = readFileSync(
resolve("./dist/workers/prod/worker-facade.js"),
// join(cliRootPath(), "workers", "prod", "worker-facade.js"),
"utf-8"
);
const workerFacade = readFileSync(resolve("./dist/workers/prod/worker-facade.js"), "utf-8");

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

let workerContents = workerFacade
Expand Down Expand Up @@ -74,7 +64,6 @@ export async function compile(options: CompileOptions) {
const result = await build({
stdin: {
contents: workerContents,
// resolveDir: process.cwd(),
resolveDir: config.projectDir,
sourcefile: "__entryPoint.ts",
},
Expand All @@ -87,11 +76,7 @@ export async function compile(options: CompileOptions) {
platform: "node",
format: "cjs", // This is needed to support opentelemetry instrumentation that uses module patching
target: ["node18", "es2020"],
// outdir: "out",
outdir: resolve(config.projectDir, "out"),
// banner: {
// 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" } }); } });`,
// },
footer: {
js: "process.exit();",
},
Expand All @@ -112,31 +97,18 @@ export async function compile(options: CompileOptions) {
});

if (result.errors.length > 0) {
// compileSpinner.stop("Build failed, aborting deployment");

// span.setAttributes({
// "build.workerErrors": result.errors.map(
// (error) => `Error: ${error.text} at ${error.location?.file}`
// ),
// });

throw new Error("Build failed, aborting deployment");
}

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

const entryPointContents = readFileSync(
resolve("./dist/workers/prod/entry-point.js"),
// join(cliRootPath(), "workers", "prod", "entry-point.js"),
"utf-8"
);
const entryPointContents = readFileSync(resolve("./dist/workers/prod/entry-point.js"), "utf-8");

const entryPointResult = await build({
stdin: {
contents: entryPointContents,
// resolveDir: process.cwd(),
resolveDir: config.projectDir,
sourcefile: "index.ts",
},
Expand All @@ -150,7 +122,6 @@ export async function compile(options: CompileOptions) {
packages: "external",
format: "cjs", // This is needed to support opentelemetry instrumentation that uses module patching
target: ["node18", "es2020"],
// outdir: "out",
outdir: resolve(config.projectDir, "out"),
define: {
__PROJECT_CONFIG__: JSON.stringify(config),
Expand All @@ -161,14 +132,6 @@ export async function compile(options: CompileOptions) {
});

if (entryPointResult.errors.length > 0) {
// compileSpinner.stop("Build failed, aborting deployment");

// span.setAttributes({
// "build.entryPointErrors": entryPointResult.errors.map(
// (error) => `Error: ${error.text} at ${error.location?.file}`
// ),
// });

throw new Error("Build failed, aborting deployment");
}

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

// Create a tmp directory to store the build
// const tempDir = await createTempDir();

logger.debug(`Writing compiled files to ${tempDir}`);

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

// Get the metaOutput for the entryPoint build
// const entryPointMetaOutput =
// entryPointResult.metafile!.outputs[posix.join("out", "stdin.js")];
const entryPointMetaOutput =
entryPointResult.metafile!.outputs[
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-v3/e2e/createDeployHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type CreateDeployHashOptions = {
};

export async function createDeployHash(options: CreateDeployHashOptions) {
const { entryPointOutputFile, workerOutputFile } = options;
const { dependencies, entryPointOutputFile, workerOutputFile } = options;

// COPIED FROM compileProject()
const contentHasher = createHash("sha256");
Expand Down
63 changes: 63 additions & 0 deletions packages/cli-v3/e2e/fixtures.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export interface TestCase {
resolveEnv?: { [key: string]: string };
id: string;
skipTypecheck?: boolean;
wantConfigNotFoundError?: boolean;
wantConfigInvalidError?: boolean;
wantCompilationError?: boolean;
wantWorkerError?: boolean;
wantDependenciesError?: boolean;
wantInstallationError?: boolean;
}

export const fixturesConfig: TestCase[] = [
{
id: "config-invalid",
wantConfigInvalidError: true,
},
{
id: "config-not-found",
wantConfigNotFoundError: true,
},
{
id: "dep-to-add-scope-parsing",
skipTypecheck: true,
},
{
id: "infisical-sdk",
skipTypecheck: true,
// Should not fail
wantCompilationError: true,
},
{
id: "lock-nested-peer-deps",
skipTypecheck: true,
resolveEnv: {
npm_config_legacy_peer_deps: "true",
},
},
{
id: "resolve-legacy-peer-deps",
skipTypecheck: true,
// Should fail with better error at resolve
wantWorkerError: true,
},
{
id: "resolve-trigger-deps",
skipTypecheck: true,
},
{
id: "server-only",
skipTypecheck: true,
},
{
id: "trigger-dir-missing",
skipTypecheck: true,
},
{
id: "trigger-dir-not-found",
skipTypecheck: true,
// Should fail way before
wantCompilationError: true,
},
];

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "no-config",
"name": "config-invalid",
"private": true,
"packageManager": "[email protected]+sha256.4b4efa12490e5055d59b9b9fc9438b7d581a6b7af3b5675eb5c5f447cee1a589",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli-v3/e2e/fixtures/config-invalid/trigger.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const config = {
// 'project' field is mandatory
triggerDirectories: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ __metadata:
version: 8
cacheKey: 10c0

"no-config@workspace:.":
"config-invalid@workspace:.":
version: 0.0.0-use.local
resolution: "no-config@workspace:."
resolution: "config-invalid@workspace:."
languageName: unknown
linkType: soft
1 change: 1 addition & 0 deletions packages/cli-v3/e2e/fixtures/config-not-found/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
14 changes: 14 additions & 0 deletions packages/cli-v3/e2e/fixtures/config-not-found/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/cli-v3/e2e/fixtures/config-not-found/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "config-not-found",
"private": true,
"packageManager": "[email protected]+sha256.4b4efa12490e5055d59b9b9fc9438b7d581a6b7af3b5675eb5c5f447cee1a589",
"engines": {
"pnpm": "8.15.5",
"yarn": "4.2.2"
}
}
9 changes: 9 additions & 0 deletions packages/cli-v3/e2e/fixtures/config-not-found/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# https://github.com/pnpm/pnpm/issues/2412
12 changes: 12 additions & 0 deletions packages/cli-v3/e2e/fixtures/config-not-found/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 8
cacheKey: 10c0

"config-not-found@workspace:.":
version: 0.0.0-use.local
resolution: "config-not-found@workspace:."
languageName: unknown
linkType: soft
Loading
Loading