chore: only test changed packages (#1194)

This commit is contained in:
Roland Hummel
2022-10-20 15:59:09 +02:00
committed by GitHub
parent 73bf91d7e1
commit 16fa774012
6 changed files with 24 additions and 9 deletions

View File

@ -12,6 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
@ -20,8 +21,13 @@ jobs:
- name: 📦 Install dependencies
run: npm ci
- name: 🧪 Run tests
run: npm test
- name: 🧪 Run all tests
if: ${{ github.event_name == 'push' }}
run: npm run test
- name: 🧪 Run tests for changed files only
if: ${{ github.event_name == 'pull_request' }}
run: npm run test-changed
- name: 💄 Code style
run: npm run style

View File

@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
npm run style
npm run test
npm run test-changed

View File

@ -63,7 +63,8 @@ should add unique value.
#### Module System
We use the [ES Module](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) system, which bring an official, standardized module system to JavaScript.
We use the [ES Module](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) system, which bring an
official, standardized module system to JavaScript.
It roughly means you will need to use `export` and `import` statements instead of `module.exports` and `require()`.
@ -71,7 +72,7 @@ It roughly means you will need to use `export` and `import` statements instead o
Be confident that your code works. When was the last time you committed a code change, your build failed, and half of
your app stopped working? Mine was last week. Writing tests for our Algorithms will help us ensure the implementations
are air tight even after multiple fixes and code changes.
are airtight even after multiple fixes and code changes.
We use [Jest](https://jestjs.io/) to run unit tests on our algorithms. It provides a very readable and expressive way to
structure your test code.
@ -107,6 +108,12 @@ You can also start Jest in "watch" mode:
npm test -- --watchAll
```
We also prepared a helper script that runs tests only for changed files:
```shell
npm run test-changed
```
This will run all tests and watch source and test files for changes. When a change is made, the tests will run again.
#### Coding Style

View File

@ -1,10 +1,10 @@
import { problem44 } from '../Problem044.js'
describe('checking nth prime number', () => {
it('should be invalid input if number is negative', () => {
test('should be invalid input if number is negative', () => {
expect(() => problem44(-3)).toThrowError('Invalid Input')
})
it('should be invalid input if number is 0', () => {
test('should be invalid input if number is 0', () => {
expect(() => problem44(0)).toThrowError('Invalid Input')
})
// Project Euler Condition Check
@ -12,6 +12,7 @@ describe('checking nth prime number', () => {
expect(problem44(1)).toBe(5482660)
})
// Project Euler Second Value for Condition Check
// FIXME skip this test for now because it runs very long and clogs up the CI & pre-commit hook
test('if the number is greater or equal to 2167', () => {
expect(problem44(2167)).toBe(8476206790)
})

2
package-lock.json generated
View File

@ -23,7 +23,7 @@
"standard": "^17.0.0"
},
"engines": {
"node": ">=18"
"node": ">=16.6.0"
}
},
"node_modules/@ampproject/remapping": {

View File

@ -4,7 +4,8 @@
"type": "module",
"description": "A repository for All algorithms implemented in Javascript (for educational purposes only)",
"scripts": {
"test": "jest --no-cache",
"test": "jest",
"test-changed": "jest --onlyChanged",
"style": "standard",
"prepare": "husky install"
},