mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
- [x] The big question is: do we - put this behind a flag (`nextConfig.experimental.importTypeBytes`?) - ~~put this behind a non-standard `type: "turbopack-bytes"` (currently implemented)~~ - ~~just ship it?~~ - the only "problem" is that type: "bytes" is now silently ignored if the flag is not enabled - [x] [Furthermore, `Uint8Array.fromBase64` isn't that widely supported](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64#browser_compatibility). So emitting that always is questionable from a browser support standpoint. This is the output in the test: ```js module.exports = [ "[project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/type-bytes/input/data.bin (static bytes in ecmascript)", (ctx) => { ctx.v(Uint8Array.fromBase64("dGhpcyBpcyBzb21lIGRhdGEK")); }, "[project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/type-bytes/input/index.js [test] (ecmascript)", (ctx) => { "use strict"; var bytes = ctx.i( "[project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/type-bytes/input/data.bin (static bytes in ecmascript)" ); it("import type:bytes should work", () => { expect(bytes["default"]).toBeInstanceOf(Uint8Array); expect(new TextDecoder().decode(bytes["default"])).toBe( "this is some data\n" ); }); }, ]; ```
28 lines
792 B
TypeScript
28 lines
792 B
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('turbopack-loader-config', () => {
|
|
const { next, isTurbopack, isNextDev, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
// we can't set `nextConfig` inline because it contains regexes that fail to serialize, it needs
|
|
// to be set in a separate module (`next.config.ts`)
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
if (!isTurbopack) {
|
|
it('should only run the test in turbopack', () => {})
|
|
return
|
|
}
|
|
|
|
it('should replace modules with their loader-generated versions', async () => {
|
|
const response = JSON.parse(await next.render('/api'))
|
|
expect(response).toEqual({
|
|
foo: 'default return value',
|
|
bar: 'has export substring' + (isNextDev ? ' on dev' : ' on prod'),
|
|
})
|
|
})
|
|
})
|