-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
8 changed files
with
1,196 additions
and
39 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
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,28 @@ | ||
const { readdirSync } = require("fs"); | ||
const { join } = require("path"); | ||
|
||
const pkgList = readdirSync(join(__dirname, "./packages")).filter( | ||
(pkg) => pkg.charAt(0) !== "." | ||
); | ||
|
||
const moduleNameMapper = { | ||
"\\.(css|less|sass|scss)$": require.resolve("identity-obj-proxy"), | ||
}; | ||
|
||
pkgList.forEach((shortName) => { | ||
const name = `@fortune-sheet/${shortName}`; | ||
moduleNameMapper[name] = join(__dirname, `./packages/${shortName}/src`); | ||
}); | ||
|
||
module.exports = { | ||
collectCoverageFrom: ["packages/**/src/**/*.{ts,tsx}"], | ||
testEnvironment: "jsdom", | ||
moduleNameMapper, | ||
moduleFileExtensions: ["js", "jsx", "cjs", "ts", "tsx"], | ||
transform: { | ||
"\\.(t|j)sx?$": require.resolve("./tests/transformer"), | ||
}, | ||
unmockedModulePathPatterns: ["node_modules/react/", "node_modules/enzyme/"], | ||
verbose: true, | ||
setupFiles: ["./tests/setup.js"], | ||
}; |
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,12 @@ | ||
import { mount } from "enzyme"; | ||
import React from "react"; | ||
import { Workbook } from "@fortune-sheet/react"; | ||
import { waitForComponentToPaint } from "./util"; | ||
|
||
describe("Worksheet", () => { | ||
it("should render", async () => { | ||
const wrapper = mount(<Workbook data={[{ name: "Sheet1" }]} />); | ||
await waitForComponentToPaint(wrapper); | ||
expect(wrapper.exists(".fortune-sheet-container")).toBeTruthy(); | ||
}); | ||
}); |
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,67 @@ | ||
import Enzyme from "enzyme"; | ||
import Adapter from "@wojtekmaj/enzyme-adapter-react-17"; | ||
import "jest-canvas-mock"; | ||
|
||
import React from "react"; | ||
|
||
global.React = React; | ||
|
||
jest.mock("react", () => ({ | ||
...jest.requireActual("react"), | ||
useLayoutEffect: jest.requireActual("react").useEffect, | ||
})); | ||
|
||
jest.setTimeout(60000); | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
Object.defineProperty(window, "open", { | ||
value: jest.fn, | ||
}); | ||
|
||
global.requestAnimationFrame = | ||
global.requestAnimationFrame || | ||
function requestAnimationFrame(cb) { | ||
return setTimeout(cb, 0); | ||
}; | ||
|
||
global.cancelAnimationFrame = | ||
global.cancelAnimationFrame || | ||
function cancelAnimationFrame() { | ||
return null; | ||
}; | ||
|
||
// browserMocks.js | ||
export const localStorageMock = (() => { | ||
let store = { | ||
locale: "zh", | ||
}; | ||
|
||
return { | ||
getItem(key) { | ||
return store[key] || null; | ||
}, | ||
setItem(key, value) { | ||
store[key] = value.toString(); | ||
}, | ||
removeItem(key) { | ||
store[key] = null; | ||
}, | ||
clear() { | ||
store = {}; | ||
}, | ||
}; | ||
})(); | ||
|
||
Object.defineProperty(window, "localStorage", { | ||
value: localStorageMock, | ||
writable: true, | ||
}); | ||
|
||
Object.defineProperty(window, "cancelAnimationFrame", { | ||
value: () => null, | ||
}); | ||
|
||
Math.random = () => 0.8404419276253765; | ||
|
||
global.URL.createObjectURL = () => {}; |
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,9 @@ | ||
const babel = require("babel-jest"); | ||
|
||
module.exports = babel.default.createTransformer({ | ||
presets: [ | ||
require.resolve("@babel/preset-typescript"), | ||
"@babel/preset-react", | ||
["@babel/preset-env", { targets: { node: "current" } }], | ||
], | ||
}); |
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,12 @@ | ||
import { act } from "react-dom/test-utils"; | ||
|
||
export const waitForComponentToPaint = async (wrapper: any, time = 50) => { | ||
// @ts-ignore | ||
await act(async () => { | ||
wrapper.update?.(); | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, time); | ||
}); | ||
wrapper.update?.(); | ||
}); | ||
}; |
Oops, something went wrong.