1
- import { extractConfigFromFile } from '../packages/runtime/src/helpers/analysis'
1
+ import { extractConfigFromFile } from '../../ packages/runtime/src/helpers/analysis'
2
2
import { resolve } from 'pathe'
3
- import { getDependenciesOfFile } from '../packages/runtime/src/helpers/files'
4
- import { dirname } from 'path'
3
+
5
4
describe ( 'static source analysis' , ( ) => {
6
5
beforeEach ( ( ) => {
7
6
// Spy on console.error
@@ -12,81 +11,72 @@ describe('static source analysis', () => {
12
11
; ( console . error as jest . Mock ) . mockRestore ( )
13
12
} )
14
13
it ( 'should extract config values from a source file' , async ( ) => {
15
- const config = await extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/background.js' ) )
14
+ const config = await extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/background.js' ) )
16
15
expect ( config ) . toEqual ( {
17
16
type : 'experimental-background' ,
18
17
} )
19
18
} )
20
19
it ( 'should extract config values from a TypeScript source file' , async ( ) => {
21
- const config = await extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/background.ts' ) )
20
+ const config = await extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/background.ts' ) )
22
21
expect ( config ) . toEqual ( {
23
22
type : 'experimental-background' ,
24
23
} )
25
24
} )
26
25
it ( 'should return an empty config if not defined' , async ( ) => {
27
- const config = await extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/missing.ts' ) )
26
+ const config = await extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/missing.ts' ) )
28
27
expect ( config ) . toEqual ( { } )
29
28
} )
30
29
31
30
it ( 'should return an empty config if config is invalid' , async ( ) => {
32
- const config = await extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/invalid.ts' ) )
31
+ const config = await extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/invalid.ts' ) )
33
32
expect ( config ) . toEqual ( { } )
34
33
} )
35
34
36
35
it ( 'should extract schedule values from a source file' , async ( ) => {
37
- const config = await extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/scheduled.ts' ) )
36
+ const config = await extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/scheduled.ts' ) )
38
37
expect ( config ) . toEqual ( {
39
38
type : 'experimental-scheduled' ,
40
39
schedule : '@daily' ,
41
40
} )
42
41
} )
43
42
it ( 'should throw if schedule is provided when type is background' , async ( ) => {
44
- await expect ( extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/background-schedule.ts' ) ) ) . rejects . toThrow (
43
+ await expect ( extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/background-schedule.ts' ) ) ) . rejects . toThrow (
45
44
'Unsupported config value in test/fixtures/analysis/background-schedule.ts' ,
46
45
)
47
46
expect ( console . error ) . toHaveBeenCalledWith (
48
47
`Invalid config value in test/fixtures/analysis/background-schedule.ts: schedule is not allowed unless type is "experimental-scheduled"` ,
49
48
)
50
49
} )
51
50
it ( 'should throw if schedule is provided when type is default' , async ( ) => {
52
- await expect ( extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/default-schedule.ts' ) ) ) . rejects . toThrow (
51
+ await expect ( extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/default-schedule.ts' ) ) ) . rejects . toThrow (
53
52
'Unsupported config value in test/fixtures/analysis/default-schedule.ts' ,
54
53
)
55
54
expect ( console . error ) . toHaveBeenCalledWith (
56
55
`Invalid config value in test/fixtures/analysis/default-schedule.ts: schedule is not allowed unless type is "experimental-scheduled"` ,
57
56
)
58
57
} )
59
58
it ( 'should throw if schedule is not provided when type is scheduled' , async ( ) => {
60
- await expect ( extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/missing-schedule.ts' ) ) ) . rejects . toThrow (
59
+ await expect ( extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/missing-schedule.ts' ) ) ) . rejects . toThrow (
61
60
'Unsupported config value in test/fixtures/analysis/missing-schedule.ts' ,
62
61
)
63
62
expect ( console . error ) . toHaveBeenCalledWith (
64
63
`Invalid config value in test/fixtures/analysis/missing-schedule.ts: schedule is required when type is "experimental-scheduled"` ,
65
64
)
66
65
} )
67
66
it ( 'should throw if edge runtime is specified for scheduled functions' , async ( ) => {
68
- await expect ( extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/scheduled-edge.ts' ) ) ) . rejects . toThrow (
67
+ await expect ( extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/scheduled-edge.ts' ) ) ) . rejects . toThrow (
69
68
'Unsupported config value in test/fixtures/analysis/scheduled-edge.ts' ,
70
69
)
71
70
expect ( console . error ) . toHaveBeenCalledWith (
72
71
`Invalid config value in test/fixtures/analysis/scheduled-edge.ts: edge runtime is not supported for scheduled functions` ,
73
72
)
74
73
} )
75
74
it ( 'should throw if edge runtime is specified for background functions' , async ( ) => {
76
- await expect ( extractConfigFromFile ( resolve ( __dirname , 'fixtures/analysis/background-edge.ts' ) ) ) . rejects . toThrow (
75
+ await expect ( extractConfigFromFile ( resolve ( __dirname , '../ fixtures/analysis/background-edge.ts' ) ) ) . rejects . toThrow (
77
76
'Unsupported config value in test/fixtures/analysis/background-edge.ts' ,
78
77
)
79
78
expect ( console . error ) . toHaveBeenCalledWith (
80
79
`Invalid config value in test/fixtures/analysis/background-edge.ts: edge runtime is not supported for background functions` ,
81
80
)
82
81
} )
83
82
} )
84
-
85
- describe ( 'dependency tracing' , ( ) => {
86
- it ( 'generates dependency list from a source file' , async ( ) => {
87
- const dependencies = await getDependenciesOfFile ( resolve ( __dirname , 'fixtures/analysis/background.js' ) )
88
- expect ( dependencies ) . toEqual (
89
- [ 'test/webpack-api-runtime.js' , 'package.json' ] . map ( ( dep ) => resolve ( dirname ( __dirname ) , dep ) ) ,
90
- )
91
- } )
92
- } )
0 commit comments