1- import { extractConfigFromFile } from '../packages/runtime/src/helpers/analysis'
1+ import { extractConfigFromFile } from '../../ packages/runtime/src/helpers/analysis'
22import { resolve } from 'pathe'
3- import { getDependenciesOfFile } from '../packages/runtime/src/helpers/files'
4- import { dirname } from 'path'
3+
54describe ( 'static source analysis' , ( ) => {
65 beforeEach ( ( ) => {
76 // Spy on console.error
@@ -12,81 +11,72 @@ describe('static source analysis', () => {
1211 ; ( console . error as jest . Mock ) . mockRestore ( )
1312 } )
1413 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' ) )
1615 expect ( config ) . toEqual ( {
1716 type : 'experimental-background' ,
1817 } )
1918 } )
2019 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' ) )
2221 expect ( config ) . toEqual ( {
2322 type : 'experimental-background' ,
2423 } )
2524 } )
2625 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' ) )
2827 expect ( config ) . toEqual ( { } )
2928 } )
3029
3130 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' ) )
3332 expect ( config ) . toEqual ( { } )
3433 } )
3534
3635 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' ) )
3837 expect ( config ) . toEqual ( {
3938 type : 'experimental-scheduled' ,
4039 schedule : '@daily' ,
4140 } )
4241 } )
4342 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 (
4544 'Unsupported config value in test/fixtures/analysis/background-schedule.ts' ,
4645 )
4746 expect ( console . error ) . toHaveBeenCalledWith (
4847 `Invalid config value in test/fixtures/analysis/background-schedule.ts: schedule is not allowed unless type is "experimental-scheduled"` ,
4948 )
5049 } )
5150 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 (
5352 'Unsupported config value in test/fixtures/analysis/default-schedule.ts' ,
5453 )
5554 expect ( console . error ) . toHaveBeenCalledWith (
5655 `Invalid config value in test/fixtures/analysis/default-schedule.ts: schedule is not allowed unless type is "experimental-scheduled"` ,
5756 )
5857 } )
5958 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 (
6160 'Unsupported config value in test/fixtures/analysis/missing-schedule.ts' ,
6261 )
6362 expect ( console . error ) . toHaveBeenCalledWith (
6463 `Invalid config value in test/fixtures/analysis/missing-schedule.ts: schedule is required when type is "experimental-scheduled"` ,
6564 )
6665 } )
6766 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 (
6968 'Unsupported config value in test/fixtures/analysis/scheduled-edge.ts' ,
7069 )
7170 expect ( console . error ) . toHaveBeenCalledWith (
7271 `Invalid config value in test/fixtures/analysis/scheduled-edge.ts: edge runtime is not supported for scheduled functions` ,
7372 )
7473 } )
7574 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 (
7776 'Unsupported config value in test/fixtures/analysis/background-edge.ts' ,
7877 )
7978 expect ( console . error ) . toHaveBeenCalledWith (
8079 `Invalid config value in test/fixtures/analysis/background-edge.ts: edge runtime is not supported for background functions` ,
8180 )
8281 } )
8382} )
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