mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
chore: only test changed packages (#1194)
This commit is contained in:
10
.github/workflows/Ci.yml
vendored
10
.github/workflows/Ci.yml
vendored
@ -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
|
||||
|
@ -2,4 +2,4 @@
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run style
|
||||
npm run test
|
||||
npm run test-changed
|
||||
|
@ -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()`.
|
||||
|
||||
@ -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
|
||||
|
@ -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
2
package-lock.json
generated
@ -23,7 +23,7 @@
|
||||
"standard": "^17.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=16.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
|
@ -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"
|
||||
},
|
||||
|
Reference in New Issue
Block a user