refactor(Cypress): add nodemodules

This commit is contained in:
2021-09-02 17:18:41 +02:00
parent 1aa57bbd0a
commit bc6e1bc12e
4238 changed files with 340975 additions and 8 deletions

View File

@@ -0,0 +1,98 @@
const browserify = require("@cypress/browserify-preprocessor");
const { default: preprocessor, transform } = require(".");
jest.mock("@cypress/browserify-preprocessor");
const { defaultOptions } = jest.requireActual(
"@cypress/browserify-preprocessor"
);
describe("Preprocessor", () => {
beforeEach(() => {
browserify.defaultOptions = defaultOptions;
browserify.mockReturnValue(() => {});
});
afterEach(() => {
browserify.mockClear();
});
it("should use Cypress browserify options by default", async () => {
await preprocessor()({ shouldWatch: false });
global.jestExpect(browserify).toHaveBeenCalledWith({
...defaultOptions,
browserifyOptions: {
...defaultOptions.browserifyOptions,
transform: [transform, ...defaultOptions.browserifyOptions.transform],
},
});
});
it("should add transform when other transforms are defined in options", async () => {
await preprocessor({
browserifyOptions: {
transform: ["babelify"],
},
})({ shouldWatch: false });
global.jestExpect(browserify).toHaveBeenCalledWith({
browserifyOptions: {
transform: [transform, "babelify"],
},
});
});
it("should preserve transforms in options when our transform is already included", async () => {
const options = {
browserifyOptions: {
extensions: ["js", "ts"],
plugins: [["tsify"]],
transform: ["aliasify", transform, "babelify"],
},
};
await preprocessor(options)({ shouldWatch: false });
global.jestExpect(browserify).toHaveBeenCalledWith(options);
});
it("should add our transform when no other transforms are defined in options", async () => {
const options = {
browserifyOptions: {
extensions: ["js", "ts"],
plugins: [["tsify"]],
},
};
await preprocessor(options)({ shouldWatch: false });
global.jestExpect(browserify).toHaveBeenCalledWith({
...options,
browserifyOptions: {
...options.browserifyOptions,
transform: [transform],
},
});
});
it("should add our transform when browserifyOptions property is not passed to options", async () => {
const options = { unsupported: true };
await preprocessor(options)({ shouldWatch: false });
global.jestExpect(browserify).toHaveBeenCalledWith({
...options,
browserifyOptions: {
transform: [transform],
},
});
});
it("should fail gracefully when options is not an object", () => {
const err = new Error("Preprocessor options must be an object");
global.jestExpect(() => preprocessor("options")).toThrow(err);
global.jestExpect(() => preprocessor(1)).toThrow(err);
global.jestExpect(() => preprocessor(false)).toThrow(err);
});
});