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/.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 cbf45db..48516ad 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,11 +33,9 @@ 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 + - 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/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/package.json b/package.json index 93120f4..db53502 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'", + "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", 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))'); + }); +}); 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', () => {