Skip to content

Commit 1b6c494

Browse files
committed
add 'import js as thing' tests
1 parent 0dd5d8f commit 1b6c494

11 files changed

Lines changed: 76 additions & 75 deletions

File tree

test/e2e/turbopack-import-type-bytes/app/api/route.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/e2e/turbopack-import-type-bytes/index.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/e2e/turbopack-import-type-text/app/api/route.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/e2e/turbopack-import-type-text/index.test.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/e2e/turbopack-import-type-text/next.config.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import text from './data.txt' with { type: 'text' }
2+
import jsAsText from './some.js' with { type: 'text' }
3+
import bytes from './data.bin' with { type: 'bytes' }
4+
import jsAsBytes from './some.js' with { type: 'bytes' }
5+
6+
export async function GET(_req) {
7+
return Response.json(
8+
{
9+
text: {
10+
typeofString: typeof text === 'string',
11+
length: text.length,
12+
content: text,
13+
},
14+
jsAsText: {
15+
typeofString: typeof jsAsText === 'string',
16+
content: jsAsText,
17+
},
18+
bytes: {
19+
instanceofUint8Array: bytes instanceof Uint8Array,
20+
length: bytes.length,
21+
content: new TextDecoder().decode(bytes),
22+
},
23+
jsAsBytes: {
24+
instanceofUint8Array: jsAsBytes instanceof Uint8Array,
25+
content: new TextDecoder().decode(jsAsBytes),
26+
},
27+
},
28+
{ status: 200 }
29+
)
30+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const nope = 'nope'
2+
3+
throw new Error('please dont execute me')
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
const jsContent = `export const nope = 'nope'
4+
5+
throw new Error('please dont execute me')
6+
`
7+
8+
describe('turbopack-import-with-type', () => {
9+
const { next, skipped } = nextTestSetup({
10+
files: __dirname,
11+
skipDeployment: true,
12+
})
13+
14+
if (skipped) {
15+
return
16+
}
17+
18+
// Testing this together on one route ensures we also avoid weird duplicate module ident things
19+
it('supports import with type: text and type: bytes', async () => {
20+
const response = JSON.parse(await next.render('/api'))
21+
expect(response).toEqual({
22+
text: {
23+
typeofString: true,
24+
length: 12,
25+
content: 'hello world\n',
26+
},
27+
jsAsText: {
28+
typeofString: true,
29+
content: jsContent,
30+
},
31+
bytes: {
32+
instanceofUint8Array: true,
33+
length: 18,
34+
content: 'this is some data\n',
35+
},
36+
jsAsBytes: {
37+
instanceofUint8Array: true,
38+
content: jsContent,
39+
},
40+
})
41+
})
42+
})

0 commit comments

Comments
 (0)