From ec034cdd56d7b2d91439861af61c9cb00ba347f7 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sat, 15 Oct 2022 20:19:33 +0200 Subject: [PATCH 1/9] Skip test that's running suuuuuuuper-long Relates to #1193 --- Project-Euler/test/Problem044.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project-Euler/test/Problem044.test.js b/Project-Euler/test/Problem044.test.js index bf6cccd60e..fa9e25e7f0 100644 --- a/Project-Euler/test/Problem044.test.js +++ b/Project-Euler/test/Problem044.test.js @@ -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,7 +12,7 @@ describe('checking nth prime number', () => { expect(problem44(1)).toBe(5482660) }) // Project Euler Second Value for Condition Check - test('if the number is greater or equal to 2167', () => { + test.skip('if the number is greater or equal to 2167', () => { expect(problem44(2167)).toBe(8476206790) }) }) From 1a6c6c475e72ee7c926713b373cb561173b231bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sat, 15 Oct 2022 20:42:53 +0200 Subject: [PATCH 2/9] Add FIXME annotation --- Project-Euler/test/Problem044.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Project-Euler/test/Problem044.test.js b/Project-Euler/test/Problem044.test.js index fa9e25e7f0..1a7baee362 100644 --- a/Project-Euler/test/Problem044.test.js +++ b/Project-Euler/test/Problem044.test.js @@ -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.skip('if the number is greater or equal to 2167', () => { expect(problem44(2167)).toBe(8476206790) }) From 46c74abb40234275e839993c2f6cebbc84eb5ffd Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 16 Oct 2022 20:50:07 +0200 Subject: [PATCH 3/9] Attempt to run tests only for changed files --- .husky/pre-commit | 2 +- Project-Euler/test/Problem044.test.js | 2 +- package-lock.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 35ea7e3c08..56d5b8a49e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,4 +2,4 @@ . "$(dirname "$0")/_/husky.sh" npm run style -npm run test +npm run test -- --onlyChanged diff --git a/Project-Euler/test/Problem044.test.js b/Project-Euler/test/Problem044.test.js index 1a7baee362..b542b3db6d 100644 --- a/Project-Euler/test/Problem044.test.js +++ b/Project-Euler/test/Problem044.test.js @@ -13,7 +13,7 @@ describe('checking nth prime number', () => { }) // 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.skip('if the number is greater or equal to 2167', () => { + test('if the number is greater or equal to 2167', () => { expect(problem44(2167)).toBe(8476206790) }) }) diff --git a/package-lock.json b/package-lock.json index aee3c01889..53a83cf06d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "standard": "^17.0.0" }, "engines": { - "node": ">=18" + "node": ">=16.6.0" } }, "node_modules/@ampproject/remapping": { From 3ed415c29ee5704c829a7db3881f1ded4e355569 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 16 Oct 2022 20:55:03 +0200 Subject: [PATCH 4/9] Add npm script for running jest on changed files only --- .husky/pre-commit | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 56d5b8a49e..9b70cd5958 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,4 +2,4 @@ . "$(dirname "$0")/_/husky.sh" npm run style -npm run test -- --onlyChanged +npm run test-changed diff --git a/package.json b/package.json index 2fdd75f06c..6ab94ac09e 100644 --- a/package.json +++ b/package.json @@ -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" }, From 76a359864a9858710ae9e8abf5dd20fc4528dc15 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 16 Oct 2022 21:01:08 +0200 Subject: [PATCH 5/9] Add information about test-changed script to contribution docs --- CONTRIBUTING.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7386f9dca9..4598b8d3e5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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-watch +``` + 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 From 86afd1f67adee641de2d29261075acc8c2f62434 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 16 Oct 2022 22:26:31 +0200 Subject: [PATCH 6/9] Only run tests for changed files in CI, too --- .github/workflows/Ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Ci.yml b/.github/workflows/Ci.yml index 8d41203145..a75f0d17f7 100644 --- a/.github/workflows/Ci.yml +++ b/.github/workflows/Ci.yml @@ -21,7 +21,7 @@ jobs: run: npm ci - name: ๐Ÿงช Run tests - run: npm test + run: npm run test-changed - name: ๐Ÿ’„ Code style run: npm run style From 09e48264973c90aadf9c8deef1ef5b39b9237d68 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Mon, 17 Oct 2022 13:12:54 +0200 Subject: [PATCH 7/9] Fix contributing info --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4598b8d3e5..8415cfe5ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -111,7 +111,7 @@ npm test -- --watchAll We also prepared a helper script that runs tests only for changed files: ```shell -npm run test-watch +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. From bbd3d8cf05511f3675000868738156c6d6232189 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Mon, 17 Oct 2022 22:26:46 +0200 Subject: [PATCH 8/9] Run all tests on push to master, run only changed files' tests on PRs --- .github/workflows/Ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Ci.yml b/.github/workflows/Ci.yml index a75f0d17f7..b0e1687e39 100644 --- a/.github/workflows/Ci.yml +++ b/.github/workflows/Ci.yml @@ -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 run test-changed + - 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 - name: ๐Ÿ’„ Code style run: npm run style From 50134f8e802afa30c0d2b7ef4563b490249bd204 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Wed, 19 Oct 2022 15:46:52 +0200 Subject: [PATCH 9/9] Fix CI for PRs (test-changed instead of test) --- .github/workflows/Ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Ci.yml b/.github/workflows/Ci.yml index b0e1687e39..a783e0bb97 100644 --- a/.github/workflows/Ci.yml +++ b/.github/workflows/Ci.yml @@ -27,7 +27,7 @@ jobs: - name: ๐Ÿงช Run tests for changed files only if: ${{ github.event_name == 'pull_request' }} - run: npm run test + run: npm run test-changed - name: ๐Ÿ’„ Code style run: npm run style pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy