File tree Expand file tree Collapse file tree 6 files changed +19
-8
lines changed
packages/adapter-cloudflare/test Expand file tree Collapse file tree 6 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1
1
import { read } from '$app/server' ;
2
- import goose from '../../../../goose.jpg ' ;
2
+ import file from '../../../../../file.txt?url ' ;
3
3
4
4
export function GET ( ) {
5
- return read ( goose ) ;
5
+ return read ( file ) ;
6
6
}
Original file line number Diff line number Diff line change
1
+ import path from 'node:path' ;
2
+ import { fileURLToPath } from 'node:url' ;
3
+ import fs from 'node:fs/promises' ;
1
4
import { expect , test } from '@playwright/test' ;
2
5
6
+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
7
+
3
8
test ( 'worker works' , async ( { page } ) => {
4
9
await page . goto ( '/' ) ;
5
10
await expect ( page . locator ( 'h1' ) ) . toContainText ( 'Sum: 3' ) ;
6
11
} ) ;
7
12
8
13
test ( "('$app/server').read works" , async ( { page } ) => {
14
+ const filecontent = await fs . readFile ( path . resolve ( __dirname , '../../../file.txt' ) , 'utf-8' ) ;
9
15
const response = await page . goto ( '/read' ) ;
10
- expect ( response . status ( ) ) . toBe ( 200 ) ;
11
- expect ( response . headers ( ) [ 'content-type' ] ) . toBe ( 'image/jpeg' ) ;
16
+ expect ( await response . text ( ) ) . toBe ( filecontent ) ;
12
17
} ) ;
Original file line number Diff line number Diff line change 1
1
import { read } from '$app/server' ;
2
- import goose from '../../../../goose.jpg ' ;
2
+ import file from '../../../../../file.txt?url ' ;
3
3
4
4
export function GET ( ) {
5
- return read ( goose ) ;
5
+ return read ( file ) ;
6
6
}
Original file line number Diff line number Diff line change
1
+ import path from 'node:path' ;
2
+ import { fileURLToPath } from 'node:url' ;
3
+ import fs from 'node:fs/promises' ;
1
4
import { expect , test } from '@playwright/test' ;
2
5
6
+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
7
+
3
8
test ( 'worker works' , async ( { page } ) => {
4
9
await page . goto ( '/' ) ;
5
10
await expect ( page . locator ( 'h1' ) ) . toContainText ( 'Sum: 3' ) ;
6
11
} ) ;
7
12
8
13
test ( "('$app/server').read works" , async ( { page } ) => {
14
+ const filecontent = await fs . readFile ( path . resolve ( __dirname , '../../../file.txt' ) , 'utf-8' ) ;
9
15
const response = await page . goto ( '/read' ) ;
10
- expect ( response . status ( ) ) . toBe ( 200 ) ;
11
- expect ( response . headers ( ) [ 'content-type' ] ) . toBe ( 'image/jpeg' ) ;
16
+ expect ( await response . text ( ) ) . toBe ( filecontent ) ;
12
17
} ) ;
Original file line number Diff line number Diff line change
1
+ Hello! This file is read by `('$app/server').read`.
You can’t perform that action at this time.
0 commit comments