Skip to content

Commit

Permalink
test(cra): Add testing example
Browse files Browse the repository at this point in the history
The comments in `tsconfig.paths.json` had to be removed because they
don't work with `require()`.

Closes #159. Closes #160.
  • Loading branch information
NiGhTTraX committed Dec 23, 2021
1 parent 19a8b1c commit 1e35ebe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions examples/cra/craco.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const { pathsToModuleNameMapper } = require("ts-jest");
const { compilerOptions } = require("./tsconfig.paths.json");

module.exports = {
eslint: { enable: false },
Expand Down Expand Up @@ -55,4 +57,14 @@ module.exports = {
],
},
},
jest: {
configure: {
preset: "ts-jest",

moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
// This has to match the baseUrl defined in tsconfig.json.
prefix: "<rootDir>/",
}),
},
},
};
3 changes: 2 additions & 1 deletion examples/cra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"scripts": {
"start": "cross-env SKIP_PREFLIGHT_CHECK=true craco start",
"build": "cross-env SKIP_PREFLIGHT_CHECK=true craco build"
"build": "cross-env SKIP_PREFLIGHT_CHECK=true craco build",
"test": "cross-env SKIP_PREFLIGHT_CHECK=true craco test --watchAll=false"
},
"browserslist": {
"production": [
Expand Down
10 changes: 10 additions & 0 deletions examples/cra/src/components/app.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import { render } from "react-dom";
import { App } from "./app";

describe("App", () => {
it("should render without crashing", () => {
const div = document.createElement("div");
render(<App />, div);
});
});
2 changes: 0 additions & 2 deletions examples/cra/tsconfig.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
"baseUrl": ".",

"paths": {
/* Redefine the root path aliases relative to this package. */
"@nighttrax/components/*": ["../../packages/components/src/*"],
"@nighttrax/*": ["../../packages/*/src"],

/* Define aliases specific to this package. */
"@components/*": ["./src/components/*"],
"@hooks/*": ["./src/hooks/*"]
}
Expand Down

0 comments on commit 1e35ebe

Please sign in to comment.