-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(jobs): Add e2e test script and CI job (#11348)
Adds a test script which will do an end-to-end style test of the redwood jobs feature. It takes a test project, sets up up jobs, generates a job, schedules a job, and executes the job. It can be run locally with just one command. It has been added to CI too. --------- Co-authored-by: Rob Cameron <cannikin@fastmail.com>
- Loading branch information
1 parent
974a245
commit a13b44f
Showing
6 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# E2E Background jobs | ||
|
||
This script runs an E2E style test against the Redwood Jobs feature. Testing that jobs can be setup, generated, scheduled and executed. | ||
|
||
## Usage | ||
|
||
You can run this locally by creating a test project: | ||
|
||
```bash | ||
yarn build:test-project ../rw-test-project | ||
``` | ||
|
||
Then you can execute the script like so: | ||
|
||
```bash | ||
yarn e2e:background-jobs ../rw-test-project | ||
``` | ||
|
||
You will likely find it helpful to set up git in the test project so you can easily rollback the project to the default state if you need to rerun the test multiple times. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export const SAMPLE_JOB_PERFORM_ARGS = `async (location: string, data: string)` | ||
|
||
export const SAMPLE_JOB_PERFORM_BODY = ` | ||
const { default: fs } = await import('node:fs') | ||
fs.writeFileSync(location, data) | ||
` | ||
|
||
export const SAMPLE_FUNCTION = ` | ||
import type { APIGatewayEvent, Context } from 'aws-lambda' | ||
import { SampleJob } from 'src/jobs/SampleJob/SampleJob' | ||
import { later } from 'src/lib/jobs' | ||
export const handler = async (event: APIGatewayEvent, _context: Context) => { | ||
const { location, data } = JSON.parse(event.body) | ||
await later(SampleJob, [location as string, data as string]) | ||
return { | ||
statusCode: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
location, | ||
data, | ||
}), | ||
} | ||
} | ||
` | ||
|
||
export const JOBS_SCRIPT = ` | ||
import { db } from 'api/src/lib/db' | ||
export default async () => { | ||
const jobs = await db.backgroundJob.findMany() | ||
console.log(JSON.stringify(jobs)) | ||
} | ||
` | ||
|
||
export const PRISMA_SCRIPT = ` | ||
import { db } from 'api/src/lib/db' | ||
export default async () => { | ||
const model = db.backgroundJob | ||
console.log( | ||
JSON.stringify({ | ||
name: model.name, | ||
}) | ||
) | ||
} | ||
` |
Oops, something went wrong.