Skip to content

Commit

Permalink
Preserve file name tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Beny committed Feb 23, 2024
1 parent 2b7af7c commit 30de433
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7453,6 +7453,69 @@ addEventListener('fetch', event => {});`
`);
});

it("should be able to preserve file names when defining rules for uploading non-js modules (sw)", async () => {
writeWranglerToml({
rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }],
preserve_file_names: true,
});
fs.writeFileSync("./index.js", `import TEXT from './text.file';`);
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
mockSubDomainRequest();
mockUploadWorkerRequest({
expectedType: "sw",
expectedBindings: [
{
name: "__text_file",
part: "__text_file",
type: "text_blob",
},
],
expectedModules: {
__text_file: "SOME TEXT CONTENT",
},
});
await runWrangler("deploy index.js");
expect(std.out).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`""`);
});

it("should be able to preserve file names when defining rules for uploading non-js modules (esm)", async () => {
writeWranglerToml({
rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }],
preserve_file_names: true,
});
fs.writeFileSync(
"./index.js",
`import TEXT from './text.file'; export default {};`
);
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
mockSubDomainRequest();
mockUploadWorkerRequest({
expectedType: "esm",
expectedBindings: [],
expectedModules: {
"./text.file": "SOME TEXT CONTENT",
},
});
await runWrangler("deploy index.js");
expect(std.out).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`""`);
});

describe("inject process.env.NODE_ENV", () => {
let actualProcessEnvNodeEnv: string | undefined;
beforeEach(() => {
Expand Down

0 comments on commit 30de433

Please sign in to comment.