Correct issue with TS after tsconfig split with unit tests (#9686)

* Correct file test naming

* Correct test files import and names

* Restructure TS configuration with shared path

* Copied TS configuration for shell due current architecture state
This commit is contained in:
Giuseppe Leo 2023-12-12 11:35:38 +01:00 committed by GitHub
parent 8eb172cdbe
commit cb6f806274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 218 additions and 168 deletions

View File

@ -1 +1,2 @@
// NOTE: We import the babel config from the shell folder due to "Validate Plugin build system" setup set in this way
module.exports = require('./shell/babel.config.js');

96
cypress/globals.d.ts vendored
View File

@ -19,63 +19,65 @@ export type CreateUserParams = {
}
}
// eslint-disable-next-line no-unused-vars
declare namespace Cypress {
interface Chainable {
declare global {
// eslint-disable-next-line no-unused-vars
namespace Cypress {
interface Chainable {
state(state: any): any;
state(state: any): any;
login(username?: string, password?: string, cacheSession?: boolean): Chainable<Element>;
logout(): Chainable;
byLabel(label: string): Chainable<Element>;
login(username?: string, password?: string, cacheSession?: boolean): Chainable<Element>;
logout(): Chainable;
byLabel(label: string): Chainable<Element>;
createUser(params: CreateUserParams): Chainable;
setGlobalRoleBinding(userId: string, role: string): Chainable;
setClusterRoleBinding(clusterId: string, userPrincipalId: string, role: string): Chainable;
setProjectRoleBinding(clusterId: string, userPrincipalId: string, projectName: string, role: string): Chainable;
getProjectByName(clusterId: string, projectName: string): Chainable;
createProject(projName: string, clusterId: string, userId: string): Chainable;
createNamespace(nsName: string, projId: string): Chainable;
createUser(params: CreateUserParams): Chainable;
setGlobalRoleBinding(userId: string, role: string): Chainable;
setClusterRoleBinding(clusterId: string, userPrincipalId: string, role: string): Chainable;
setProjectRoleBinding(clusterId: string, userPrincipalId: string, projectName: string, role: string): Chainable;
getProjectByName(clusterId: string, projectName: string): Chainable;
createProject(projName: string, clusterId: string, userId: string): Chainable;
createNamespace(nsName: string, projId: string): Chainable;
getRancherResource(prefix: 'v3' | 'v1', resourceType: string, resourceId?: string, expectedStatusCode: string): Chainable;
setRancherResource(prefix: 'v3' | 'v1', resourceType: string, resourceId: string, body: string): Chainable;
deleteRancherResource(prefix: 'v3' | 'v1', resourceType: string, resourceId: string): Chainable;
getRancherResource(prefix: 'v3' | 'v1', resourceType: string, resourceId?: string, expectedStatusCode: string): Chainable;
setRancherResource(prefix: 'v3' | 'v1', resourceType: string, resourceId: string, body: string): Chainable;
deleteRancherResource(prefix: 'v3' | 'v1', resourceType: string, resourceId: string): Chainable;
/**
* Wrapper for cy.get() to simply define the data-testid value that allows you to pass a matcher to find the element.
* @param id Value used for the data-testid attribute of the element.
* @param matcher Matching character used for attribute value:
* - `$`: Suffixed with this value
* - `^`: Prefixed with this value
* - `~`: Contains this value as whitespace separated words
* - `*`: Contains this value
*/
getId(id: string, matcher?: Matcher): Chainable<Element>;
/**
* Wrapper for cy.get() to simply define the data-testid value that allows you to pass a matcher to find the element.
* @param id Value used for the data-testid attribute of the element.
* @param matcher Matching character used for attribute value:
* - `$`: Suffixed with this value
* - `^`: Prefixed with this value
* - `~`: Contains this value as whitespace separated words
* - `*`: Contains this value
*/
getId(id: string, matcher?: Matcher): Chainable<Element>;
/**
* Wrapper for cy.find() to simply define the data-testid value that allows you to pass a matcher to find the element.
* @param id Value used for the data-testid attribute of the element.
* @param matcher Matching character used for attribute value:
* - `$`: Suffixed with this value
* - `^`: Prefixed with this value
* - `~`: Contains this value as whitespace separated words
* - `*`: Contains this value
*/
findId(id: string, matcher?: Matcher): Chainable<Element>;
/**
* Wrapper for cy.find() to simply define the data-testid value that allows you to pass a matcher to find the element.
* @param id Value used for the data-testid attribute of the element.
* @param matcher Matching character used for attribute value:
* - `$`: Suffixed with this value
* - `^`: Prefixed with this value
* - `~`: Contains this value as whitespace separated words
* - `*`: Contains this value
*/
findId(id: string, matcher?: Matcher): Chainable<Element>;
/**
* Override user preferences to default values, allowing to pass custom preferences for a deterministic scenario
* Leave empty for reset to default values
*/
// eslint-disable-next-line no-undef
userPreferences(preferences?: Partial<UserPreferences>): Chainable<null>;
/**
* Override user preferences to default values, allowing to pass custom preferences for a deterministic scenario
* Leave empty for reset to default values
*/
// eslint-disable-next-line no-undef
userPreferences(preferences?: Partial<UserPreferences>): Chainable<null>;
requestBase64Image(url: string): Chainable;
requestBase64Image(url: string): Chainable;
keyboardControls(triggerKeys: Partial<any>, count: number): Chainable<Element>;
keyboardControls(triggerKeys: Partial<any>, count: number): Chainable<Element>;
interceptAllRequests(verbs: Verbs, urls: string[], timeout: number): Chainable<string>;
interceptAllRequests(verbs: Verbs, urls: string[], timeout: number): Chainable<string>;
iFrame(): Chainable<Element>;
iFrame(): Chainable<Element>;
}
}
}

View File

@ -1,6 +1,20 @@
{
"extends": "../shell/tsconfig.default.json",
"extends": "../tsconfig.paths.json",
"target": "ES2018",
"module": "ES2020",
"moduleResolution": "Node",
"lib": [
"ES2020",
"ES2020.AsyncIterable",
"DOM"
],
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": false,
"compilerOptions": {
"esModuleInterop": true,
"baseUrl": "..",
"noEmit": true,
"types": [
"cypress",

View File

@ -1,13 +1,17 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['./jest.setup.js'],
modulePaths: [
'<rootDir>'
],
watchman: false,
// tell Jest to handle `*.vue` files
moduleFileExtensions: ['js', 'json', 'vue', 'ts'],
watchman: false,
moduleNameMapper: {
// Paths
// NOTE: Docs configuration does not work for our environment
// https://kulshekhar.github.io/ts-jest/docs/27.1/getting-started/paths-mapping#jest-config-with-helper
modulePaths: ['<rootDir>'],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/$1',
'^~~/(.*)$': '<rootDir>/$1',
'^@/(.*)$': '<rootDir>/$1',
@ -15,21 +19,6 @@ module.exports = {
'@pkg/(.*)': '<rootDir>/pkg/$1',
'@components/(.*)': '<rootDir>/pkg/rancher-components/src/components/$1',
},
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest', // process js with `babel-jest`
'.*\\.(vue)$': '<rootDir>/node_modules/@vue/vue2-jest', // process `*.vue` files with `vue-jest`
'^.+\\.tsx?$': 'ts-jest', // process `*.ts` files with `ts-jest`
'^.+\\.svg$': '<rootDir>/svgTransform.js' // to mock `*.svg` files
},
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
collectCoverage: false,
collectCoverageFrom: [
'<rootDir>/shell/**/*.{vue,ts,js}',
'<rootDir>/pkg/rancher-components/src/components/**/*.{vue,ts,js}',
'!<rootDir>/shell/scripts/',
'!<rootDir>/.nuxt',
'!<rootDir>/.nuxt-prod',
],
modulePathIgnorePatterns: [
'<rootDir>/cypress/',
'<rootDir>/scripts/',
@ -44,13 +33,26 @@ module.exports = {
'<rootDir>/node_modules/',
'<rootDir>(/.*)*/__tests__/utils/',
],
coverageDirectory: '<rootDir>/coverage/unit',
coverageReporters: ['json', 'text-summary'],
globals: {
'ts-jest': {
isolatedModules: true,
tsconfig: 'tsconfig.test.json'
}
// Babel
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest', // process js with `babel-jest`
'.*\\.(vue)$': '<rootDir>/node_modules/@vue/vue2-jest', // process `*.vue` files with `vue-jest`
'^.+\\.tsx?$': 'ts-jest', // process `*.ts` files with `ts-jest`
'^.+\\.svg$': '<rootDir>/svgTransform.js' // to mock `*.svg` files
},
preset: 'ts-jest'
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
// Coverage
coverageDirectory: '<rootDir>/coverage/unit',
coverageReporters: ['json', 'text-summary'],
collectCoverage: false,
collectCoverageFrom: [
'<rootDir>/shell/**/*.{vue,ts,js}',
'<rootDir>/pkg/rancher-components/src/components/**/*.{vue,ts,js}',
'!<rootDir>/shell/scripts/',
],
// Globals
globals: { 'ts-jest': { isolatedModules: true } },
};

View File

@ -10,7 +10,13 @@ module.exports = function(api) {
{ targets: { node: 'current' } }
]
];
const env = { test: { presets: [['@babel/env', { targets: { node: 'current' } }]] } };
const env = {
test: {
presets: [[
'@babel/env', { targets: { node: 'current' } }
]]
}
};
const plugins = [];

View File

@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils';
import PolicyRuleTarget from '@shell/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget';
import { cleanHtmlDirective } from '@shell/plugins/clean-html-directive';
import mock from '@shell/edit/networking.k8s.io.networkpolicy/__tests__/utils/mock.json';
import { PolicyRuleTargetSelectors } from '@shell/edit/networking.k8s.io.networkpolicy/__tests__/utils/selectors';
import { PolicyRuleTargetSelectors } from '@shell/edit/networking.k8s.io.networkpolicy/__tests__/utils/selectors.test.ts';
describe.each([
'view',

View File

@ -1,4 +1,4 @@
import { batchChanges } from '@shell/plugins/dashboard-store/mutations';
import { batchChanges } from '@shell/plugins/dashboard-store/mutations.js';
import { POD, WORKLOAD_TYPES } from '@shell/config/types';
import Resource from '@shell/plugins/dashboard-store/resource-class';

View File

@ -1,46 +0,0 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": false,
"baseUrl": ".",
"rootDir": ".",
"paths": {
"~/*": [
"../*"
],
"@/*": [
"../*"
],
"@shell/*": [
"../shell/*"
],
"@pkg/*": [
"../shell/pkg/*"
]
},
"typeRoots": [
"./node_modules/@types"
],
},
"exclude": [
"node_modules",
".nuxt",
"dist",
"dist-pkg",
"shell/creators",
"shell/scripts",
"script/standalone",
"docusaurus"
]
}

View File

@ -1,16 +1,42 @@
{
"extends": "./tsconfig.default.json",
"extends": "./tsconfig.paths.json",
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": false,
"esModuleInterop": true,
"baseUrl": ".",
"rootDir": ".",
"types": [
"@types/node",
"@types/jest",
"@nuxt/types",
]
"node",
"jest",
],
"typeRoots": [
"./node_modules/@types",
"../node_modules/@types"
],
},
"exclude": [
"cypress",
"./cypress.config.ts",
"**/*.test.ts",
"**/*.spec.ts"
"node_modules",
".nuxt",
"dist",
"dist-pkg",
"../dist",
"../dist-pkg",
"../creators",
"../scripts",
"../cypress",
"../cypress.config.ts",
"../docusaurus",
"../**/*.spec.ts"
]
}

18
shell/tsconfig.paths.json Normal file
View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"paths": {
"~/*": [
"../*"
],
"@/*": [
"../*"
],
"@shell/*": [
"../shell/*"
],
"@pkg/*": [
"../shell/pkg/*"
]
},
},
}

View File

@ -1,19 +1,3 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["@types/node", "@types/jest"]
},
"exclude": [
"node_modules",
".nuxt",
"dist",
"dist-pkg",
"cypress",
"shell/creators",
"shell/scripts",
"cypress",
"./cypress.config.ts",
"docusaurus",
"script/standalone"
]
"extends": "../tsconfig.json"
}

View File

@ -1,3 +1,41 @@
{
"extends": "./shell/tsconfig.default.json",
"extends": "./tsconfig.paths.json",
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": false,
"esModuleInterop": true,
"baseUrl": ".",
"rootDir": ".",
"types": [
"node",
"jest",
],
"typeRoots": [
"./node_modules/@types"
],
},
"exclude": [
"node_modules",
".nuxt",
"dist",
"dist-pkg",
"cypress",
"shell/creators",
"shell/scripts",
"cypress",
"./cypress.config.ts",
"docusaurus",
"scripts/standalone",
"**/*.spec.ts"
]
}

21
tsconfig.paths.json Normal file
View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"paths": {
"~/*": [
"*"
],
"@/*": [
"*"
],
"@shell/*": [
"shell/*"
],
"@pkg/*": [
"shell/pkg/*"
],
"@components/*": [
"pkg/rancher-components/src/components/*"
]
},
},
}

View File

@ -1,16 +0,0 @@
{
"extends": "./shell/tsconfig.default.json",
"compilerOptions": {
"types": [
"jest"
]
},
"include": [
"./**/*.test.ts"
],
"exclude": [
"cypress",
"./cypress.config.ts",
"**/*.spec.ts"
]
}