-
Notifications
You must be signed in to change notification settings - Fork 340
/
scheduled-functions.test.ts
49 lines (39 loc) · 1.61 KB
/
scheduled-functions.test.ts
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
import { describe, expect, test } from 'vitest'
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
import fetch from 'node-fetch'
import { pause } from '../../utils/pause.js'
describe('scheduled functions', () => {
setupFixtureTests('dev-server-with-functions', { devServer: true }, () => {
test<FixtureTestContext>('should emulate next_run for scheduled functions', async ({ devServer }) => {
const response = await fetch(`http://localhost:${devServer.port}/.netlify/functions/scheduled-v2`, {})
expect(response.status).toBe(200)
})
})
setupFixtureTests('dev-server-with-functions', { devServer: true }, () => {
test<FixtureTestContext>('should detect file changes to scheduled function', async ({ devServer, fixture }) => {
const body = await fetch(`http://localhost:${devServer.port}/.netlify/functions/ping`, {}).then((res) =>
res.text(),
)
expect(body).toBe('ping')
await fixture.builder
.withContentFile({
path: 'functions/ping.js',
content: `
const { schedule } = require('@netlify/functions')
module.exports.handler = schedule("@daily", async () => {
return {
statusCode: 200,
body: "test"
}
})`,
})
.build()
const DETECT_FILE_CHANGE_DELAY = 500
await pause(DETECT_FILE_CHANGE_DELAY)
const warning = await fetch(`http://localhost:${devServer.port}/.netlify/functions/ping`, {}).then((res) =>
res.text(),
)
expect(warning).toContain('Your function returned `body`')
})
})
})