Skip to content

Commit 0d90756

Browse files
committed
feat: configuration de test avec jest
1 parent 55f7528 commit 0d90756

File tree

8 files changed

+16500
-7073
lines changed

8 files changed

+16500
-7073
lines changed

app/components/Home/home.component.spec.ts

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { HeaderComponent } from "./Header.component";
2+
3+
describe('headercomponent', () => {
4+
test('should have valid snapshot', () => {
5+
expect(HeaderComponent.template).toMatchSnapshot();
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`headercomponent should have valid snapshot 1`] = `
4+
"<header>
5+
<img src="./chucknorris_logo.png" alt="chucknorris" />
6+
</header>"
7+
`;

app/mocks/file-mock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

html-loader-preprocessor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
process(src) {
3+
const escapedSrc = src
4+
.replace(/`/g, '\\`')
5+
.replace(/\\/g, '\\\\')
6+
.replace(/\$(?=\{.*?\})/g, '\\$');
7+
8+
return { code: `module.exports = \`${escapedSrc}\`` };
9+
},
10+
};

jest.config.js

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after the first failure
9+
// bail: false,
10+
11+
// Respect "browser" field in package.json when resolving modules
12+
// browser: false,
13+
14+
// The directory where Jest should store its cached dependency information
15+
// cacheDirectory: "C:\\Users\\S641122\\AppData\\Local\\Temp\\jest",
16+
17+
// Automatically clear mock calls and instances between every test
18+
clearMocks: true,
19+
20+
// Indicates whether the coverage information should be collected while executing the test
21+
collectCoverage: false,
22+
23+
// An array of glob patterns indicating a set of files for which coverage information should be collected
24+
collectCoverageFrom: [
25+
'app/**/*.(js|jsx|ts|tsx)',
26+
'!app/**/*.spec.(js|jsx|ts|tsx)',
27+
'!app/**/*.html',
28+
],
29+
30+
// The directory where Jest should output its coverage files
31+
coverageDirectory: 'coverage\\Jest',
32+
33+
// An array of regexp pattern strings used to skip coverage collection
34+
// coveragePathIgnorePatterns: [
35+
// "\\\\node_modules\\\\"
36+
// ],
37+
38+
coverageProvider: 'v8',
39+
40+
// A list of reporter names that Jest uses when writing coverage reports
41+
coverageReporters: ['text', 'lcov'],
42+
43+
// An object that configures minimum threshold enforcement for coverage results
44+
// coverageThreshold: null,
45+
46+
// Make calling deprecated APIs throw helpful error messages
47+
// errorOnDeprecated: false,
48+
49+
// Force coverage collection from ignored files usin a array of glob patterns
50+
// forceCoverageMatch: [],
51+
52+
// A path to a module which exports an async function that is triggered once before all test suites
53+
// globalSetup: null,
54+
55+
// A path to a module which exports an async function that is triggered once after all test suites
56+
// globalTeardown: null,
57+
58+
// A set of global variables that need to be available in all test environments
59+
globals: {
60+
'ts-jest': {
61+
diagnostics: {
62+
pathRegex: /\.(spec|test)\.(ts|tsx)$/,
63+
warnOnly: true,
64+
},
65+
isolatedModules: true,
66+
},
67+
},
68+
69+
// An array of directory names to be searched recursively up from the requiring module's location
70+
// moduleDirectories: [
71+
// "node_modules"
72+
// ],
73+
74+
// An array of file extensions your modules use
75+
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node', 'html'],
76+
77+
modulePaths: ['<rootDir>/app'],
78+
79+
// A map from regular expressions to module names that allow to stub out resources with a single module
80+
moduleNameMapper: {
81+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css|scss)$': '<rootDir>/app/mocks/file-mock.js',
82+
//"\\.html$": "<rootDir>/App/mocks/file-mock.js
83+
//'^uuid$': require.resolve('uuid'),
84+
},
85+
86+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87+
// modulePathIgnorePatterns: [],
88+
89+
// Activates notifications for test results
90+
// notify: false,
91+
92+
// An enum that specifies notification mode. Requires { notify: true }
93+
// notifyMode: "always",
94+
95+
// A preset that is used as a base for Jest's configuration
96+
// preset: null,
97+
98+
// Run tests from one or more projects
99+
// projects: null,
100+
101+
// Use this configuration option to add custom reporters to Jest
102+
// reporters: undefined,
103+
104+
// Automatically reset mock state between every test
105+
// resetMocks: false,
106+
107+
// Reset the module registry before running each individual test
108+
// resetModules: false,
109+
110+
// A path to a custom resolver
111+
// resolver: null,
112+
113+
// Automatically restore mock state between every test
114+
// restoreMocks: false,
115+
116+
// The root directory that Jest should scan for tests and modules within
117+
// rootDir: null,
118+
119+
// A list of paths to directories that Jest should use to search for files in
120+
// roots: [
121+
// "<rootDir>"
122+
// ],
123+
124+
// Allows you to use a custom runner instead of Jest's default test runner
125+
// runner: "jest-runner",
126+
127+
// The paths to modules that run some code to configure or set up the testing environment before each test
128+
// setupFiles: [],
129+
130+
// The path to a module that runs some code to configure or set up the testing framework before each test
131+
// setupFilesAfterEnv: ['<rootDir>/index-specrunner.js'],
132+
133+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
134+
// snapshotSerializers: [],
135+
136+
// The test environment that will be used for testing
137+
testEnvironment: 'jest-environment-jsdom',
138+
139+
// Options that will be passed to the testEnvironment
140+
// testEnvironmentOptions: {},
141+
142+
// Adds a location field to test results
143+
// testLocationInResults: false,
144+
145+
// The glob patterns Jest uses to detect test files
146+
// testMatch: [
147+
// "**/__tests__/**/*.js?(x)",
148+
// "**/?(*.)+(spec|test).js?(x)"
149+
// ],
150+
testMatch: ['**/__tests__/**/*.(j|t)s?(x)', '**/?(*.)+(spec|test).(j|t)s?(x)'],
151+
152+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
153+
testPathIgnorePatterns: ['<rootDir>/node_modules'],
154+
155+
// The regexp pattern Jest uses to detect test files
156+
// testRegex: "",
157+
158+
// This option allows use of a custom test runner
159+
// testRunner: "jasmine2",
160+
161+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
162+
// timers: "real",
163+
164+
// A map from regular expressions to paths to transformers
165+
transform: {
166+
'^.+\\.js$': 'babel-jest',
167+
'^.+\\.(ts|tsx)$': 'ts-jest',
168+
'^.+\\.html$': '<rootDir>/html-loader-preprocessor.js',
169+
}, //,
170+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
171+
// transformIgnorePatterns: [
172+
// "\\\\node_modules\\\\"
173+
// ],
174+
175+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
176+
// unmockedModulePathPatterns: undefined,
177+
178+
// Indicates whether each individual test should be reported during the run
179+
//verbose: true,
180+
181+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
182+
// watchPathIgnorePatterns: [],
183+
184+
// Whether to use watchman for file crawling
185+
// watchman: true,
186+
};

0 commit comments

Comments
 (0)