8000 Setup testing by thien-do · Pull Request #251 · thien-do/moai · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Setup testing #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"ignorePatterns": ["node_modules", "dist", "public"],
"ignorePatterns": ["node_modules", "dist", "public", "test/coverage"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand Down
26 changes: 13 additions & 13 deletions .github/DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ To understand the principles that drive the design and development of Moai, see
| core | [@moai/core] | [Rollup] |
| gallery | [@moai/gallery] | [Rollup] |
| docs | [docs.moaijs.com] | [Storybook] |

## Local Development

To have a local development environment, run `yarn start`:

```
yarn start
```

Note that you don't need to run `yarn` first. We intentionally prefixed `yarn start` with `yarn` to ensure you always work on the correct dependencies.

This simply runs the docs site locally so you can review your changes. It imports components directly from "core" so changes you made there will be applied immediately.
| test | Test suits | [Jest] |

[@moai/core]: https://www.npmjs.com/package/@moai/core
[@moai/gallery]: https://www.npmjs.com/package/@moai/gallery
[docs.moaijs.com]: https://docs.moaijs.com
[moaijs.com]: https://moaijs.com
[storybook]: https://storybook.js.org
[jest]: https://jestjs.io
[next.js]: https://nextjs.org
[rollup]: https://rollupjs.org/guide/en/

## Development scripts

- `yarn core`: watch and build @moai/core
- `yarn docs`: start docs.moaijs.com locally
- `yarn test`: run the test suites

"docs" and "test" both rely on the output of "core"'s build, so in most cases you will need:

- a terminal to run `yarn core`, and
- a terminal to run `yarn docs` or `yarn test`
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
public
.next
.vercel
/test/coverage
3 changes: 2 additions & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"dist"
],
"scripts": {
"build": "yarn && rollup --config",
"build": "rollup --config",
"start": "rollup --config --watch",
"report": "node ./scripts/report.js",
"prepublishOnly": "yarn build"
},
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"version": "1.0.0",
"description": "Storybook Docs of Moai 🗿",
"scripts": {
"start": "yarn && BROWSER=none start-storybook --no-manager-cache -p 6006",
"build": "yarn && build-storybook -c .storybook -o public"
"start": "BROWSER=none start-storybook --no-manager-cache -p 6006",
"build": "build-storybook -c .storybook -o public"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion gallery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"example": "ts-node ./scripts/example/generate.ts",
"build": "yarn && rollup --config",
"build": "rollup --config",
"prepublishOnly": "yarn build"
},
"repository": {
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
"private": true,
"license": "MIT",
"workspaces": [
"docs",
"core",
"gallery"
"docs",
"gallery",
"test"
],
"scripts": {
"start": "cd docs && yarn start",
"lint": "eslint --max-warnings=0 . && prettier --check .",
"lint-fix": "eslint --fix . && prettier --write ."
"lint-fix": "eslint --fix . && prettier --write .",
"core": "cd core && yarn start",
"docs": "cd docs && yarn start",
"test": "cd test && yarn test"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.28.1",
Expand Down
3 changes: 3 additions & 0 deletions test/.gitignore
1E0A
Original file line numberDiff line number Diff line change
@@ -0,0 +1,3 @@
/dist
/node_modules
/coverage
10 changes: 10 additions & 0 deletions test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-env node */

// https://jestjs.io/docs/configuration
module.exports = {
collectCoverage: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testEnvironment: "jsdom",
testMatch: ["**/dist/**/*.js?(x)"],
};
19 changes: 19 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@moai/test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"scripts": {
"test": "tsc && jest"
},
"devDependencies": {
"@moai/core": "*",
"@testing-library/react": "^12.0.0",
"@types/jest": "^26.0.23",
"jest": "^27.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typescript": "^4.3.5"
}
}
13 changes: 13 additions & 0 deletions test/src/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { render } from "@testing-library/react";
import { Button } from "@moai/core";

describe("Button", () => {
test("throws if has no content", () => {
const spy = jest.spyOn(console, "error");
spy.mockImplementation(() => void 0);
expect(() => {
render(<Button />);
}).toThrowError('must have either "icon" or "children"');
spy.mockRestore();
});
});
11 changes: 11 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"isolatedModules": false,
"outDir": "dist",
"types": ["jest"]
},
"references": [{ "path": "../core" }],
"include": ["src/**/*"]
}
Loading
0