Fix Angular tests

This commit is contained in:
Valentin Palkovic 2023-12-12 15:48:02 +01:00
parent c16c125385
commit 205a339707
9 changed files with 153 additions and 877 deletions

View File

@ -1,29 +0,0 @@
module.exports = {
displayName: __dirname.split(sep).slice(-2).join(posix.sep),
preset: 'jest-preset-angular/presets/defaults-esm',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
transformIgnorePatterns: ['/node_modules/(?!@angular|rxjs|nanoid|uuid)'],
snapshotFormat: {
escapeString: true,
printBasicPrototype: true,
},
coverageDirectory: './coverage/testapp',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
'<rootDir>/src/**/?(*.)+(spec|test).[jt]s?(x)',
],
};

View File

@ -1,31 +0,0 @@
const path = require('path');
module.exports = {
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
preset: 'jest-preset-angular/presets/defaults-esm',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
transformIgnorePatterns: ['/node_modules/(?!@angular|rxjs|nanoid|uuid)'],
snapshotFormat: {
escapeString: true,
printBasicPrototype: true,
},
coverageDirectory: './coverage/testapp',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
'<rootDir>/src/**/?(*.)+(spec|test).[jt]s?(x)',
],
};

View File

@ -65,6 +65,7 @@
"webpack": "5"
},
"devDependencies": {
"@analogjs/vite-plugin-angular": "^0.2.24",
"@angular-devkit/architect": "^0.1700.5",
"@angular-devkit/build-angular": "^17.0.5",
"@angular-devkit/core": "^17.0.5",
@ -80,8 +81,7 @@
"@types/cross-spawn": "^6.0.2",
"@types/tmp": "^0.2.3",
"cross-spawn": "^7.0.3",
"jest": "^29.7.0",
"jest-preset-angular": "^13.0.1",
"jsdom": "^23.0.1",
"tmp": "^0.2.1",
"typescript": "^5.3.2",
"webpack": "5",

View File

@ -3,7 +3,7 @@ import { vi, describe, afterEach, it, expect } from 'vitest';
import { LoggerApi } from '@angular-devkit/core/src/logger';
import { take } from 'rxjs/operators';
const { runCompodoc } = require('./run-compodoc');
import { runCompodoc } from './run-compodoc';
const mockRunScript = vi.fn();

View File

@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { extractType, setCompodocJson } from './compodoc';
import { CompodocJson, Decorator } from './types';

View File

@ -0,0 +1,10 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import '@analogjs/vite-plugin-angular/setup-vitest';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import { getTestBed } from '@angular/core/testing';
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());

View File

@ -1,9 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["webpack-env", "jest", "node"],
"types": ["webpack-env", "node"],
"typeRoots": ["../../node_modules/@types", "node_modules/@types"],
"allowJs": true
},
"include": ["**/*.test.ts", "**/*.d.ts", "setup-jest.ts"]
"include": ["**/*.test.ts", "**/*.d.ts"]
}

View File

@ -1,16 +1,15 @@
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig, mergeConfig } from 'vitest/config';
import { sep, posix } from 'path';
import { createVuePlugin } from 'vite-plugin-vue2';
import { vitestCommonConfig } from '../../vitest.workspace';
export default mergeConfig(
vitestCommonConfig,
defineConfig({
export default defineConfig(({ mode }) => {
return mergeConfig(vitestCommonConfig, {
test: {
setupFiles: ['src/test-setup.ts'],
environment: 'jsdom',
name: __dirname.split(sep).slice(-2).join(posix.sep),
},
plugins: [createVuePlugin()],
})
);
});
});

File diff suppressed because it is too large Load Diff