From 5d982246e7021dc740a0f6be05bb0b355598634a Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 23 Jan 2021 14:00:57 -0600 Subject: [PATCH 01/11] Consolidate similar scripts with npm-run-all --- .github/workflows/tests.yml | 3 --- package.json | 15 +++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cbf45db..dfc6c1d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,10 +33,7 @@ jobs: - run: npm install - run: npm run lint - - run: npm run lint-demo - run: npm run build - - run: npm run build-demo - - run: npm run build-types - run: npm run test - name: Upload test coverage report to Codecov diff --git a/package.json b/package.json index 93120f4..0052dec 100644 --- a/package.json +++ b/package.json @@ -18,17 +18,19 @@ "node": ">=10" }, "scripts": { - "build": "npm run clean && babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts' && npm run build-types", - "build-demo": "wp --config demo/webpack.config.js", - "build-types": "tsc -p ./tsconfig.types.json", + "build": "run-s clean build:*", + "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", + "build:demo": "wp --config demo/webpack.config.js", + "build:types": "tsc -p ./tsconfig.types.json", "clean": "rimraf lib/*", "format": "prettier --write 'src/**'", - "lint": "tsc -p ./tsconfig.json && eslint ./src --report-unused-disable-directives --ext .js,.ts --parser-options=project:./tsconfig.json", - "lint-demo": "tsc -p ./demo/tsconfig.json && eslint ./demo --report-unused-disable-directives --ext .js,.ts --parser-options=project:./demo/tsconfig.json", + "lint": "run-s lint:*", + "lint:src": "tsc -p ./tsconfig.json && eslint ./src --report-unused-disable-directives --ext .js,.ts --parser-options=project:./tsconfig.json", + "lint:demo": "tsc -p ./demo/tsconfig.json && eslint ./demo --report-unused-disable-directives --ext .js,.ts --parser-options=project:./demo/tsconfig.json", "precommit": "pretty-quick --staged", "prepublish": "npx publish-please guard", "publish-please": "npx publish-please", - "publish-please-prereqs": "npm run lint && npm run test && npm run build", + "publish-please-prereqs": "run-s lint test build", "test": "jest --coverage" }, "jest": { @@ -60,6 +62,7 @@ "husky": "^0.14.3", "jest": "^26.0.0", "jest-when": "^2.7.0", + "npm-run-all": "^4.1.5", "prettier": "^1.13.7", "pretty-quick": "^1.6.0", "regenerator-runtime": "^0.13.3", From e24b2b34fe29df38f1d7caf75a4c7a20c25a6aa4 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 23 Jan 2021 17:13:40 -0600 Subject: [PATCH 02/11] Move Babel ignore globs into Babel config --- .babelrc | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.babelrc b/.babelrc index 0bc78bd..11a8a70 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,4 @@ { - "presets": ["@babel/env", "@babel/preset-typescript"] + "presets": ["@babel/env", "@babel/preset-typescript"], + "ignore": ["**/*.spec.js", "**/*.spec.ts"] } diff --git a/package.json b/package.json index 0052dec..db53502 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "scripts": { "build": "run-s clean build:*", - "build:src": "babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.js','**/*.spec.ts'", + "build:src": "babel src -d lib --extensions '.js,.ts'", "build:demo": "wp --config demo/webpack.config.js", "build:types": "tsc -p ./tsconfig.types.json", "clean": "rimraf lib/*", From 04000e9981bb9db9a49b4a06024d54db47f7fd62 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 23 Jan 2021 18:35:50 -0600 Subject: [PATCH 03/11] Use testpack to test npm publish --- .editorconfig | 4 ++++ .github/workflows/tests.yml | 1 + 2 files changed, 5 insertions(+) diff --git a/.editorconfig b/.editorconfig index 4eb6462..29cb3d0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,6 +9,10 @@ end_of_line = lf insert_final_newline = true indent_style = tab +[*.yml] +indent_style = space +indent_size = 2 + [package.json] indent_style = space indent_size = 2 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dfc6c1d..fba446f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,6 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test + - run: npx testpack-cli - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From cf76a2c42d2a92b82f0914c168a4e24aeb53882e Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 23 Jan 2021 19:18:42 -0600 Subject: [PATCH 04/11] Load all test dependencies in testpack --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fba446f..46057dc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli + - run: npx testpack-cli --install jest-when regex-to-strings ts-jest - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 1f7f39602d82673f2a3351d464b5bd2ecaf34a67 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 23 Jan 2021 19:54:24 -0600 Subject: [PATCH 05/11] Fix testpack CLI syntax --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 46057dc..d7921cd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --install jest-when regex-to-strings ts-jest + - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest} **/*.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 00089633df48b67b0a4c3b33ffb14b3d00d49c89 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sat, 23 Jan 2021 22:04:36 -0600 Subject: [PATCH 06/11] Keep TypeScript dependency in testpack --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d7921cd..3de7798 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest} **/*.spec.ts + - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest,typescript} **/*.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 1373860f438ae04e0b3cd52bfaecdedd22f09c7b Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 24 Jan 2021 01:05:26 -0600 Subject: [PATCH 07/11] Fix testpack import transformations Otherwise testpack creates paths like "strings-to-regex/types/charTrie" which are invalid without the "lib" sub-directory. --- .github/workflows/tests.yml | 2 +- demo/src/demo.ts | 2 +- src/index.spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3de7798..cec123d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest,typescript} **/*.spec.ts + - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest,typescript} -r={|\.\.?|$P|,|\.\.?([\/\\].*)|$P/lib$1|} **/*.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 diff --git a/demo/src/demo.ts b/demo/src/demo.ts index 13a2e18..d23c85a 100644 --- a/demo/src/demo.ts +++ b/demo/src/demo.ts @@ -1,4 +1,4 @@ -import { condense, condenseIgnoreCase } from '../../src/index'; +import { condense, condenseIgnoreCase } from '../../src'; import { autoExpandTextarea } from './utils/auto-expand-field'; import { parseString, WhitespaceHandling } from './utils/wordList'; diff --git a/src/index.spec.ts b/src/index.spec.ts index 2b23931..99cc60e 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -2,7 +2,7 @@ import { when } from 'jest-when'; import { CharTrie } from './types/charTrie'; import * as patternUtils from './utils/pattern'; import * as trieUtils from './utils/trie'; -import { condense, condenseIgnoreCase } from './index'; +import { condense, condenseIgnoreCase } from '.'; describe('condense', () => { it('builds pattern from trie of words', () => { From ad88ee38744ef0365666662680fa1b0d961015f4 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 24 Jan 2021 01:27:23 -0600 Subject: [PATCH 08/11] Quote import replacement Regex given to testpack --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cec123d..b78f609 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest,typescript} -r={|\.\.?|$P|,|\.\.?([\/\\].*)|$P/lib$1|} **/*.spec.ts + - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest,typescript} --replace-import={'#\.\.?#$P#','#\.\.?([\/\\].*)#$P/lib$1#'} **/*.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 From 9f9b524fd84ccddc3991fd9666e23ed5f21cb607 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 24 Jan 2021 11:35:07 -0600 Subject: [PATCH 09/11] Simplify testpack with dedicated end-to-end tests --- .github/workflows/tests.yml | 2 +- src/e2e.spec.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/e2e.spec.ts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b78f609..48516ad 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - run: npm run lint - run: npm run build - run: npm run test - - run: npx testpack-cli --keep={jest-when,regex-to-strings,ts-jest,typescript} --replace-import={'#\.\.?#$P#','#\.\.?([\/\\].*)#$P/lib$1#'} **/*.spec.ts + - run: npx testpack-cli --keep={ts-jest,typescript} src/e2e.spec.ts - name: Upload test coverage report to Codecov uses: codecov/codecov-action@v1 diff --git a/src/e2e.spec.ts b/src/e2e.spec.ts new file mode 100644 index 0000000..5baea60 --- /dev/null +++ b/src/e2e.spec.ts @@ -0,0 +1,21 @@ +import { condense, condenseIgnoreCase } from '.'; + +describe('condense end-to-end', () => { + it('builds a case-sensitive RegEx to match strings', () => { + const stringsToMatch = ['foo', 'foobar', 'Foo', 'fooBarBaz']; + const matcher = condense(stringsToMatch); + + expect(matcher).toHaveProperty('flags', ''); + expect(matcher).toHaveProperty('source', '(foo(|bar|BarBaz)|Foo)'); + }); +}); + +describe('condenseIgnoreCase end-to-end', () => { + it('builds a case-insensitive RegEx to match strings', () => { + const stringsToMatch = ['foo', 'foobar', 'Foo', 'fooBarBaz']; + const matcher = condenseIgnoreCase(stringsToMatch); + + expect(matcher).toHaveProperty('flags', 'i'); + expect(matcher).toHaveProperty('source', 'foo(|bar(|baz))'); + }); +}); From 2c8ef43698d8e4576c1fb4c389553dff3aac860b Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 24 Jan 2021 11:42:41 -0600 Subject: [PATCH 10/11] Confirm testpack catches publish errors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db53502..33ece3b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "main": "lib/index.js", "types": "./lib/index.d.ts", "files": [ - "lib/" + "lib-break/" ], "sideEffects": false, "engines": { From 8be810c23c5fe93ea8a89ca63f56c96de0cb2cae Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Sun, 24 Jan 2021 11:48:09 -0600 Subject: [PATCH 11/11] Revert "Confirm testpack catches publish errors" This reverts commit 2c8ef43698d8e4576c1fb4c389553dff3aac860b. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33ece3b..db53502 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "main": "lib/index.js", "types": "./lib/index.d.ts", "files": [ - "lib-break/" + "lib/" ], "sideEffects": false, "engines": {