Skip to content

Commit

Permalink
test: add more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 10, 2022
1 parent b5b3c56 commit 07614e9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
72 changes: 51 additions & 21 deletions test/build/config/type/function-with-env/function-with-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("isProd: true");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/prod.js"))).toBeTruthy();
});
Expand All @@ -27,7 +27,7 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("isDev: true");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/dev.js"))).toBeTruthy();
});
Expand All @@ -44,7 +44,8 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("environment: 'production'");
expect(stdout).toContain("app: { title: 'Luffy' }");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/Luffy.js"))).toBeTruthy();
});
Expand All @@ -62,6 +63,7 @@ describe("function configuration", () => {
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("environment: 'production'");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/Atsumu.js"))).toBeTruthy();
});
Expand All @@ -78,7 +80,8 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("environment: 'multipleq'");
expect(stdout).toContain("file: 'name=is=Eren'");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/name=is=Eren.js"))).toBeTruthy();
});
Expand All @@ -95,7 +98,8 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("environment: 'dot'");
expect(stdout).toContain("'name.': 'Hisoka'");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/Hisoka.js"))).toBeTruthy();
});
Expand All @@ -112,7 +116,8 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("environment: 'dot'");
expect(stdout).toContain("'name.': true");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/true.js"))).toBeTruthy();
});
Expand All @@ -122,7 +127,7 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain(`foo: "''"`);
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/empty-string.js"))).toBeTruthy();
});
Expand All @@ -132,7 +137,7 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain(`foo: "bar=''"`);
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/new-empty-string.js"))).toBeTruthy();
});
Expand All @@ -146,28 +151,52 @@ describe("function configuration", () => {
expect(stdout).toContain("foo: undefined");
});

it('Supports env variable with "=$NON_EXISTENT_VAR" at the end', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--env", `foo=$NON_EXISTENT_VAR`], {
shell: true,
});
it('Supports env variable with "foo=undefined" at the end', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--env", `foo=undefined`]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
// should log foo: undefined
expect(stdout).toContain("foo: undefined");
// should log foo: 'undefined'
expect(stdout).toContain("foo: 'undefined'");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/undefined-foo.js"))).toBeTruthy();
});

// macOS/Linux specific syntax
if (!isWindows) {
it('Supports env variable with "foo=undefined" at the end', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--env", `foo=undefined`]);
it("Supports empty string in shell environment", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--env", "foo=\\'\\'"], {
shell: true,
});

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
// should log foo: 'undefined'
expect(stdout).toContain("foo: 'undefined'");
expect(stdout).toContain(`foo: "''"`);
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/undefined-foo.js"))).toBeTruthy();
expect(existsSync(resolve(__dirname, "./dist/empty-string.js"))).toBeTruthy();
});
it("should set the variable to undefined if empty string is not escaped in shell environment", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--env", "foo=''"], {
shell: true,
});

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`foo: undefined`);
});
it('Supports env variable with "=$NON_EXISTENT_VAR" at the end', async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
["--env", `foo=$NON_EXISTENT_VAR`],
{
shell: true,
},
);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
// should log foo: undefined
expect(stdout).toContain("foo: undefined");
});
}

Expand All @@ -183,7 +212,8 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("verboseStats: true");
expect(stdout).toContain("envMessage: true");
// check that the verbose env is respected
expect(stdout).toContain("LOG from webpack");

Expand Down Expand Up @@ -213,7 +243,7 @@ describe("function configuration", () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain("'name.': 'baz'");
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, "./dist/baz.js"))).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = (env) => {
console.log(env);
const { environment, app, file } = env;
const customName = file && file.name && file.name.is && file.name.is.this;
const appTitle = app && app.title;
Expand Down

0 comments on commit 07614e9

Please sign in to comment.