Skip to content

Commit

Permalink
tests run, it compiles, now let's see if it can be used
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-rocska committed Sep 18, 2023
1 parent e434b53 commit 2b4bd13
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 28 deletions.
9 changes: 9 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript"
}
}
}
30 changes: 15 additions & 15 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import {execSync} from "child_process";
import packageJson from "./package.json" assert {type: "json"};
import tsConfigJson from './tsconfig.json' assert {type: "json"};
import {pathsToModuleNameMapper} from "ts-jest";

let moduleNameMapper;
let modulePathIgnorePatterns;

if (process.env.TEST_AGAINST_ARTIFACTS) {
execSync(`npm run clean`);
execSync(`npm run build`);
execSync(`pnpm clean`);
execSync(`pnpm build`);
} else {
// Yes, I know there is ts-jest and its brilliant pathsToModuleNameMapper, but package.json based assures more
moduleNameMapper = Object.fromEntries(
Object
.entries(packageJson.exports)
.filter(([name, entry]) => typeof entry.import === 'string')
.map(([name, entry]) => [
`^` + name.replace(/^./, `@21gram-consulting/invertible`) + `$`,
entry
.import
.replace(/^.\/lib\//, `<rootDir>/src/`)
.replace(/\.[mc]{0,1}js$/, `.ts`)
])
Object.entries(pathsToModuleNameMapper(tsConfigJson.compilerOptions.paths))
.map(([from, to]) => [
[from, to],
[
Expand All @@ -27,8 +20,12 @@ if (process.env.TEST_AGAINST_ARTIFACTS) {
]
])
.reduce((a,b) => a.concat(b))
.map(([from, to]) => [from, `<rootDir>/${to}`])
.sort()
)
);
modulePathIgnorePatterns = [
"dist"
];
}

export default {
Expand All @@ -37,5 +34,8 @@ export default {
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
moduleNameMapper
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/test/'],
coverageReporters: ['text', 'html'],
moduleNameMapper,
modulePathIgnorePatterns,
};
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
"clean": "pnpm -r run clean && rimraf lib coverage var tmp include/*/",
"build": "pnpm -r run build",
"attw": "attw --pack",
"prepublishOnly": "npm run clean && npm run build",
"prepublishOnly": "pnpm clean && pnpm build",
"doc": "typedoc",
"lint": "eslint .",
"test": "jest",
"test:unit": "npm run test -- --testPathPattern=test/unit",
"test:uat": "npm run test -- --testPathPattern=test/uat",
"test:unit:coverage": "npm run test:unit -- --coverage --coverageDirectory=var/unit-test-coverage --collectCoverageFrom=./invertible/**/*",
"test:uat:coverage": "npm run test:uat -- --coverage --coverageDirectory=var/uat-test-coverage --collectCoverageFrom=./invertible/**/*",
"test:unit": "pnpm test -- --testPathPattern=test/unit",
"test:uat": "pnpm test -- --testPathPattern=test/uat",
"test:unit:coverage": "pnpm test:unit -- --coverage --coverageDirectory=var/unit-test-coverage --collectCoverageFrom=./invertible/**/*",
"test:uat:coverage": "pnpm test:uat -- --coverage --coverageDirectory=var/uat-test-coverage --collectCoverageFrom=./invertible/**/*",
"serve:coverage:unit": "npx serve var/unit-test-coverage/lcov-report",
"serve:coverage:uat": "npx serve var/uat-test-coverage/lcov-report"
},
Expand Down Expand Up @@ -115,6 +115,7 @@
"microbundle": "^0.15.1",
"rimraf": "^5.0.1",
"semver": "^7.5.4",
"ts-jest": "^29.1.1",
"typedoc": "^0.25.1",
"typedoc-plugin-coverage": "^2.2.0",
"typedoc-plugin-mdn-links": "^3.1.0",
Expand Down
55 changes: 55 additions & 0 deletions pnpm-lock.yaml

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

9 changes: 4 additions & 5 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
"compilerOptions": {
"paths": {
"#invertible/*": [
"src/invertible/*"
"invertible/src/*"
],
"#utility/*": [
"src/utility/*"
"utility/src/*"
],
"#pipe/*": [
"src/pipe/*"
"pipe/src/*"
]
}
},
"include": [
"./**/*.ts",
"./**/*.tsx"
"./**/*.ts"
]
}
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
"lib": [
"ESNext"
],
"outDir": "dist",
"rootDir": ".",
"baseUrl": ".",
"paths": {
"@21gram-consulting/invertible": [
"invertible/src"
"invertible/src/index.ts"
],
"@21gram-consulting/invertible/utility": [
"utility/src"
"utility/src/index.ts"
],
"@21gram-consulting/invertible/pipe": [
"pipe/src"
"pipe/src/index.ts"
]
}
},
Expand Down

0 comments on commit 2b4bd13

Please sign in to comment.