Skip to content

Commit 16fa774

Browse files
authored
chore: only test changed packages (#1194)
1 parent 73bf91d commit 16fa774

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

.github/workflows/Ci.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
15+
1516
- uses: actions/setup-node@v3
1617
with:
1718
node-version: 16
@@ -20,8 +21,13 @@ jobs:
2021
- name: 📦 Install dependencies
2122
run: npm ci
2223

23-
- name: 🧪 Run tests
24-
run: npm test
24+
- name: 🧪 Run all tests
25+
if: ${{ github.event_name == 'push' }}
26+
run: npm run test
27+
28+
- name: 🧪 Run tests for changed files only
29+
if: ${{ github.event_name == 'pull_request' }}
30+
run: npm run test-changed
2531

2632
- name: 💄 Code style
2733
run: npm run style

.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
npm run style
5-
npm run test
5+
npm run test-changed

CONTRIBUTING.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ should add unique value.
6363

6464
#### Module System
6565

66-
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.
66+
We use the [ES Module](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) system, which bring an
67+
official, standardized module system to JavaScript.
6768

6869
It roughly means you will need to use `export` and `import` statements instead of `module.exports` and `require()`.
6970

7071
#### Testing
7172

7273
Be confident that your code works. When was the last time you committed a code change, your build failed, and half of
7374
your app stopped working? Mine was last week. Writing tests for our Algorithms will help us ensure the implementations
74-
are air tight even after multiple fixes and code changes.
75+
are airtight even after multiple fixes and code changes.
7576

7677
We use [Jest](https://jestjs.io/) to run unit tests on our algorithms. It provides a very readable and expressive way to
7778
structure your test code.
@@ -107,6 +108,12 @@ You can also start Jest in "watch" mode:
107108
npm test -- --watchAll
108109
```
109110

111+
We also prepared a helper script that runs tests only for changed files:
112+
113+
```shell
114+
npm run test-changed
115+
```
116+
110117
This will run all tests and watch source and test files for changes. When a change is made, the tests will run again.
111118

112119
#### Coding Style

Project-Euler/test/Problem044.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { problem44 } from '../Problem044.js'
22

33
describe('checking nth prime number', () => {
4-
it('should be invalid input if number is negative', () => {
4+
test('should be invalid input if number is negative', () => {
55
expect(() => problem44(-3)).toThrowError('Invalid Input')
66
})
7-
it('should be invalid input if number is 0', () => {
7+
test('should be invalid input if number is 0', () => {
88
expect(() => problem44(0)).toThrowError('Invalid Input')
99
})
1010
// Project Euler Condition Check
1111
test('if the number is greater or equal to 1', () => {
1212
expect(problem44(1)).toBe(5482660)
1313
})
1414
// Project Euler Second Value for Condition Check
15+
// FIXME skip this test for now because it runs very long and clogs up the CI & pre-commit hook
1516
test('if the number is greater or equal to 2167', () => {
1617
expect(problem44(2167)).toBe(8476206790)
1718
})

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "module",
55
"description": "A repository for All algorithms implemented in Javascript (for educational purposes only)",
66
"scripts": {
7-
"test": "jest --no-cache",
7+
"test": "jest",
8+
"test-changed": "jest --onlyChanged",
89
"style": "standard",
910
"prepare": "husky install"
1011
},

0 commit comments

Comments
 (0)