Skip to content

Commit

Permalink
Chore/add jest (#88)
Browse files Browse the repository at this point in the history
update dependencies and remove unnecessary ones
setup jest and ESLint
limit CI jobs
adjust ci for new ts output directory
cc @ktrz on performance alert
  • Loading branch information
ktrz authored Dec 3, 2021
1 parent 5d6c8c4 commit 3f97db6
Show file tree
Hide file tree
Showing 33 changed files with 11,320 additions and 6,404 deletions.
91 changes: 44 additions & 47 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint",
"prettier"
],
"env": {
"es6": true,
"mocha": true,
"node": true
},
"rules": {
"prefer-spread": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"eqeqeq": "error",
"root": true,
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier", "plugin:prettier/recommended"],
"env": {
"es6": true,
"node": true
},
"rules": {
"prefer-spread": "off",
"eqeqeq": "error"
},
"ignorePatterns": ["examples/**", "dist/**"],
"overrides": [
{
"files": ["**/*.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.build.json", "./tsconfig.spec.json"]
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"@typescript-eslint/naming-convention": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/no-non-null-assertion": "error",
Expand All @@ -32,7 +28,7 @@
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
Expand All @@ -41,26 +37,27 @@
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error"
}
},
{
"files": ["test/*.ts"],
"plugins": ["jest"],
"env": {
"jest/globals": true
},
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/naming-convention": "off"
}
},
"overrides": [
{
"files": [
"test/*.ts"
],
"plugins": [
"mocha"
],
"extends": [
"plugin:mocha/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/camelcase": "off",
"mocha/no-setup-in-describe": "off",
"mocha/no-hooks-for-single-case": "off",
"mocha/no-exclusive-tests": "error"
}
}
]
{
"files": ["**/*.js"],
"env": {
"browser": true
},
"rules": {}
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/benchmarkjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
6 changes: 3 additions & 3 deletions .github/workflows/catch2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
uses: benchmark-action/github-action-benchmark@v1
with:
name: Catch2 Benchmark
tool: "catch2"
tool: 'catch2'
output-file-path: examples/catch2/benchmark_result.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: "200%"
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: "@bernedom,@rhysd"
alert-comment-cc-users: '@bernedom,@ktrz'
42 changes: 31 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: CI
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
rust:
Expand Down Expand Up @@ -31,7 +37,7 @@ jobs:
output-file-path: examples/rust/output.txt
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'Rust Benchmark'
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Rust Benchmark'
go:
name: Run Go benchmark example
runs-on: ubuntu-latest
Expand Down Expand Up @@ -61,7 +67,7 @@ jobs:
output-file-path: examples/go/output.txt
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'Go Benchmark'
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Go Benchmark'
benchmarkjs:
name: Run JavaScript benchmark example
runs-on: ubuntu-latest
Expand Down Expand Up @@ -90,7 +96,7 @@ jobs:
output-file-path: examples/benchmarkjs/output.txt
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'Benchmark.js Benchmark'
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Benchmark.js Benchmark'
pytest-benchmark:
name: Run Pytest benchmark example
runs-on: ubuntu-latest
Expand Down Expand Up @@ -125,7 +131,7 @@ jobs:
output-file-path: examples/pytest/output.json
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'Python Benchmark with pytest-benchmark'
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Python Benchmark with pytest-benchmark'
google-benchmark-framework:
name: Run Google C++ Benchmark Framework example
runs-on: ubuntu-latest
Expand Down Expand Up @@ -161,7 +167,7 @@ jobs:
output-file-path: examples/cpp/benchmark_result.json
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'C++ Benchmark'
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'C++ Benchmark'
catch2-framework:
name: Run Catch2 C++ Benchmark Framework example
runs-on: ubuntu-latest
Expand Down Expand Up @@ -191,11 +197,11 @@ jobs:
uses: ./
with:
name: Catch2 Benchmark
tool: "catch2"
tool: 'catch2'
output-file-path: examples/catch2/benchmark_result.txt
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'Catch2 Benchmark'
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Catch2 Benchmark'

only-alert-with-cache:
name: Run alert check with actions/cache
Expand Down Expand Up @@ -228,7 +234,7 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
unit-tests:
name: Run unit tests
runs-on: ubuntu-latest
Expand All @@ -242,11 +248,25 @@ jobs:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm run coverage
- name: Apply yamllint
run: |
sudo pip install yamllint
yamllint --strict .github/workflows
- uses: codecov/codecov-action@v2

lint:
name: Run linting and formatting check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npm run lint
- run: npm run format:check
2 changes: 1 addition & 1 deletion .github/workflows/commit-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
2 changes: 1 addition & 1 deletion .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
2 changes: 1 addition & 1 deletion .github/workflows/criterion-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@rhysd'
alert-comment-cc-users: '@ktrz'
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/node_modules
/src/*.js
/src/*.js.map
/examples/rust/Cargo.lock
/examples/rust/target
/examples/criterion-rs/Cargo.lock
/examples/criterion-rs/target
/test/*.js
/test/*.js.map
/scripts/*.js
/scripts/*.js.map
/.nyc_output
/coverage
/dist
/.idea
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test/data
coverage
dist
**/*.md
**/*.txt
10 changes: 9 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120
"printWidth": 120,
"overrides": [
{
"files": ["**/*.{yml,json}"],
"options": {
"tabWidth": 2
}
}
]
}
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ inputs:

runs:
using: 'node12'
main: 'src/index.js'
main: 'dist/src/index.js'
2 changes: 1 addition & 1 deletion examples/benchmarkjs/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ suite
.add('fib(20)', () => {
fib(20);
})
.on('cycle', event => {
.on('cycle', (event) => {
console.log(String(event.target));
})
.run();
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
globals: {
'ts-jest': {
tsconfig: 'tsconfig.spec.json',
},
},
preset: 'ts-jest',
testEnvironment: 'node',
};
Loading

0 comments on commit 3f97db6

Please sign in to comment.