-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build-command): report exit code 1 when compilation fails (#239)
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
.vscode/ | ||
*.swp | ||
package-lock.json | ||
.temp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const rimraf = require("rimraf"); | ||
const build = require("./build"); | ||
|
||
jest.mock("./config", () => { | ||
const path = require("path"); | ||
return { | ||
load: jest.fn(() => ({ | ||
build: { functions: path.join(".temp", "build", "lambda") }, | ||
})), | ||
loadContext: jest.fn(() => ({ environment: {} })), | ||
}; | ||
}); | ||
|
||
const buildTemp = path.join(".temp", "build"); | ||
const functions = path.join(buildTemp, "functions"); | ||
|
||
const setupFunction = (script, filename) => { | ||
fs.mkdirSync(functions, { recursive: true }); | ||
fs.writeFileSync(path.join(functions, filename), script); | ||
}; | ||
|
||
describe("build", () => { | ||
const functionsBuildOutputDir = require("./config").load().build.functions; | ||
|
||
beforeEach(() => { | ||
fs.mkdirSync(buildTemp, { recursive: true }); | ||
}); | ||
|
||
afterEach(() => { | ||
rimraf.sync(buildTemp); | ||
}); | ||
|
||
describe("run", () => { | ||
it("should return webpack stats on successful build", async () => { | ||
const script = `module.exports = () => console.log("hello world")`; | ||
setupFunction(script, "index.js"); | ||
|
||
const stats = await build.run(functions); | ||
expect(stats.compilation.errors).toHaveLength(0); | ||
expect( | ||
fs.existsSync(path.join(functionsBuildOutputDir, "index.js")) | ||
).toEqual(true); | ||
}); | ||
|
||
it("should throw error on complication errors", async () => { | ||
const script = `module.exports = () => console.log("hello`; | ||
setupFunction(script, "index.js"); | ||
|
||
expect.assertions(1); | ||
|
||
await expect(build.run(functions)).rejects.toHaveLength(1); | ||
}); | ||
|
||
it("should throw error on invalid config", async () => { | ||
const script = `module.exports = () => console.log("hello world")`; | ||
setupFunction(script, "index.js"); | ||
|
||
expect.assertions(1); | ||
|
||
await expect( | ||
build.run(functions, { | ||
userWebpackConfig: "non-existing-webpack-config.js", | ||
}) | ||
).rejects.toThrow("Cannot find module"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters