Skip to content

Commit

Permalink
test: automatic pre-commit testing (#30)
Browse files Browse the repository at this point in the history
* also, automatic camelCasing of package names when provided as CLI arguments
  • Loading branch information
valentinoli committed Jul 5, 2022
1 parent 585dee2 commit b171376
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ npm test
Run test for one or more packages:

```sh
npm run test:ts-node -- <packageNameCamelCased_1> [<packageNameCamelCased_2> ...]
npm run test:ts-node -- <package1> [<package2> ...]
```

## Package management
Expand Down
9 changes: 9 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import camelCase from 'lodash.camelcase'

export default {
'packages/*/src/**/*.ts': filenames => {
const packages = filenames
.map(filename => /packages\/([^/]+)\//.exec(filename)[1])
.map(camelCase)
// need to build before testing
return ['npm run build', `npm run test:ts-node -- ${packages.join(' ')}`]
},
'*.ts': filenames =>
// only lint changed files
`npm run lint -- --fix ${filenames.join(' ')}`,
Expand Down
130 changes: 77 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dev": "npm run webpack -- --mode=development --watch",
"build": "npm run webpack -- --mode=production",
"clean": "lerna run clean",
"test:ts-node": "node --experimental-specifier-resolution=node --loader ts-node/esm -r ts-node/register ./test.ts",
"test:ts-node": "node --experimental-specifier-resolution node --loader ts-node/esm ./test.ts",
"test": "npm run build && npm run test:ts-node",
"lerna:version": "lerna version prerelease --no-changelog",
"lerna:publish": "lerna publish from-package",
Expand All @@ -40,6 +40,7 @@
"@babel/core": "^7.16.12",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@types/lodash.camelcase": "^4.3.7",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "~5.30.4",
"@typescript-eslint/parser": "~5.30.0",
Expand All @@ -53,6 +54,7 @@
"husky": "~8.0.1",
"lerna": "~5.1.5",
"lint-staged": "^13.0.2",
"lodash.camelcase": "^4.3.0",
"prettier": "^2.6.2",
"sql-formatter": "^7.0.2",
"ts-loader": "~9.3.1",
Expand Down
8 changes: 4 additions & 4 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { Experience } from './lib/'
import * as packages from './packages'

import camelCase from 'lodash.camelcase'

function test([
name,
{
Expand Down Expand Up @@ -37,15 +39,13 @@ function test([
if (process.argv.length > 2) {
// test one or more packages
const names: string[] = process.argv.slice(2)
names.forEach(name => {
names.map(camelCase).forEach(name => {
// we expect the name to be camelCased
const module = (packages as { [key: string]: Experience })[name]
if (module) {
test([name, module])
} else {
throw new Error(`
The given package name "${name}" does not match a package.
Make sure the name is camelCased`)
throw new Error(`The name "${name}" does not match any package.`)
}
})
} else {
Expand Down

0 comments on commit b171376

Please sign in to comment.