-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { swcDir } from "../index"; | ||
|
||
jest.mock("../compile", () => ({ | ||
outputResult: jest.fn(), | ||
})); | ||
|
||
let mockComplie: any; | ||
|
||
jest.mock("../dirWorker", () => ({ | ||
__esModule: true, | ||
default: () => mockComplie(), | ||
})); | ||
|
||
const cliOptions: any = { | ||
outDir: "./.temp/", | ||
watch: false, | ||
filenames: ["./src/swcx/"], | ||
extensions: [".ts"], | ||
stripLeadingPaths: true, | ||
sync: true, | ||
}; | ||
const swcOptions: any = { | ||
jsc: { | ||
target: "esnext", | ||
externalHelpers: false, | ||
}, | ||
module: { | ||
type: "commonjs", | ||
}, | ||
}; | ||
|
||
describe("dir callbacks", () => { | ||
it("onSuccess should be called", async () => { | ||
mockComplie = () => Promise.resolve(1); // mock complie success | ||
|
||
const onSuccess = jest.fn(); | ||
const onFail = jest.fn(); | ||
|
||
await swcDir({ | ||
cliOptions: cliOptions, | ||
swcOptions: swcOptions, | ||
callbacks: { | ||
onSuccess, | ||
onFail, | ||
}, | ||
}); | ||
|
||
expect(onSuccess.mock.calls).toHaveLength(1); | ||
expect(onFail.mock.calls).toHaveLength(0); | ||
}); | ||
|
||
it("onFail should be called", async () => { | ||
mockComplie = () => Promise.reject(new Error("fail")); // mock complie fail | ||
|
||
const onSuccess = jest.fn(); | ||
const onFail = jest.fn(); | ||
|
||
await swcDir({ | ||
cliOptions: cliOptions, | ||
swcOptions: swcOptions, | ||
callbacks: { | ||
onSuccess, | ||
onFail, | ||
}, | ||
}); | ||
|
||
expect(onSuccess.mock.calls).toHaveLength(0); | ||
expect(onFail.mock.calls).toHaveLength(1); | ||
}); | ||
}); |
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