From f8e697ce4dd28ba8899adacf2fa12e33f60b2194 Mon Sep 17 00:00:00 2001 From: =?utf8?q?John=20Molakvo=C3=A6?= Date: Wed, 14 Jun 2023 10:49:40 +0200 Subject: [PATCH] feat: prepare jest upgrade and ts testing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- __mocks__/@nextcloud/auth.js | 15 + __mocks__/svg.js | 1 + tests/jestSetup.js => __tests__/jest-setup.ts | 0 custom.d.ts | 5 + jest.config.js => jest.config.ts | 42 +- package-lock.json | 389 ++++++++---------- package.json | 2 +- 7 files changed, 215 insertions(+), 239 deletions(-) create mode 100644 __mocks__/@nextcloud/auth.js create mode 100644 __mocks__/svg.js rename tests/jestSetup.js => __tests__/jest-setup.ts (100%) rename jest.config.js => jest.config.ts (70%) diff --git a/__mocks__/@nextcloud/auth.js b/__mocks__/@nextcloud/auth.js new file mode 100644 index 00000000000..ba0ae211790 --- /dev/null +++ b/__mocks__/@nextcloud/auth.js @@ -0,0 +1,15 @@ +import { c } from "tar" + +export const getCurrentUser = function() { + return { + uid: 'test', + displayName: 'Test', + isAdmin: false, + } +} + +export const getRequestToken = function() { + return 'test-token-1234' +} + +export const onRequestTokenUpdate = function() {} diff --git a/__mocks__/svg.js b/__mocks__/svg.js new file mode 100644 index 00000000000..7e40e291e33 --- /dev/null +++ b/__mocks__/svg.js @@ -0,0 +1 @@ +module.exports = 'SvgMock' diff --git a/tests/jestSetup.js b/__tests__/jest-setup.ts similarity index 100% rename from tests/jestSetup.js rename to __tests__/jest-setup.ts diff --git a/custom.d.ts b/custom.d.ts index 7f6487fb835..6a7b595c981 100644 --- a/custom.d.ts +++ b/custom.d.ts @@ -24,6 +24,11 @@ declare module '*.svg?raw' { export default content } +declare module '*.svg' { + const content: any + export default content +} + declare module '*.vue' { import Vue from 'vue' export default Vue diff --git a/jest.config.js b/jest.config.ts similarity index 70% rename from jest.config.js rename to jest.config.ts index 054ea7184d1..37432033242 100644 --- a/jest.config.js +++ b/jest.config.ts @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2020 Marco Ambrosini * * @author Marco Ambrosini @@ -19,42 +19,52 @@ * along with this program. If not, see . * */ +import type { Config } from 'jest' // TODO: find a way to consolidate this in one place, with webpack.common.js const ignorePatterns = [ - 'vue-material-design-icons', '@juliushaertl', - 'tributejs', + '@mdi/svg', '@nextcloud/vue', + 'ansi-regex', + 'char-regex', 'splitpanes', 'string-length', 'strip-ansi', - 'ansi-regex', - 'char-regex', + 'tributejs', + 'vue-material-design-icons', ] -module.exports = { - testMatch: ['/apps/*/src/**/*.(spec|test).(ts|js)'], - modulePathIgnorePatterns: ["/apps-extra/"], +const config: Config = { + testMatch: ['/**/*.(spec|test).(ts|js)'], + modulePathIgnorePatterns: [ + '/apps2/', + '/apps-extra/', + ], transformIgnorePatterns: [ 'node_modules/(?!(' + ignorePatterns.join('|') + ')/)', ], - setupFilesAfterEnv: ['/tests/jestSetup.js'], - resetMocks: false, + clearMocks: true, collectCoverageFrom: [ - '/apps/*/src/**/*.{js,vue}', + '/**/*.{js,vue}', ], + setupFilesAfterEnv: ['/__tests__/jest-setup.ts'], + testEnvironment: 'jest-environment-jsdom', + preset: 'ts-jest/presets/js-with-ts', - moduleFileExtensions: [ - 'js', - 'vue', - ], + // Allow mocking svg files + moduleDirectories: ['node_modules', '/'], + moduleNameMapper: { + '^.+\\.svg(\\?raw)?$': '/__mocks__/svg.js', + }, transform: { // process `*.js` files with `babel-jest` - '.*\\.(js)$': 'babel-jest', + '^.+\\.js$': 'babel-jest', '^.+\\.vue$': '@vue/vue2-jest', }, } + +export default config diff --git a/package-lock.json b/package-lock.json index 413174b1e53..bfe848e1acd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -128,7 +128,6 @@ "jest": "^29.0.3", "jest-environment-jsdom": "^29.5.0", "jsdoc": "^4.0.2", - "jsdom": "^22.0.0", "karma": "^6.4.2", "karma-chrome-launcher": "^3.1.1", "karma-coverage": "2.2.0", @@ -144,6 +143,7 @@ "sinon": "<= 5.0.7", "style-loader": "^3.3.1", "tar": "^6.1.15", + "ts-jest": "^29.1.0", "ts-loader": "^9.4.2", "ts-node": "^10.9.1", "tslib": "^2.5.3", @@ -7039,6 +7039,18 @@ "version": "1.0.0", "license": "ISC" }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "dev": true, @@ -8201,17 +8213,6 @@ "dev": true, "license": "MIT" }, - "node_modules/cssstyle": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "rrweb-cssom": "^0.6.0" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/csstype": { "version": "3.1.2", "license": "MIT" @@ -8452,19 +8453,6 @@ "node": ">= 12" } }, - "node_modules/data-urls": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "abab": "^2.0.6", - "whatwg-mimetype": "^3.0.0", - "whatwg-url": "^12.0.0" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/date-format": { "version": "4.0.14", "dev": true, @@ -15301,77 +15289,6 @@ "node": ">= 12" } }, - "node_modules/jsdom": { - "version": "22.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "abab": "^2.0.6", - "cssstyle": "^3.0.0", - "data-urls": "^4.0.0", - "decimal.js": "^10.4.3", - "domexception": "^4.0.0", - "form-data": "^4.0.0", - "html-encoding-sniffer": "^3.0.0", - "http-proxy-agent": "^5.0.0", - "https-proxy-agent": "^5.0.1", - "is-potential-custom-element-name": "^1.0.1", - "nwsapi": "^2.2.4", - "parse5": "^7.1.2", - "rrweb-cssom": "^0.6.0", - "saxes": "^6.0.0", - "symbol-tree": "^3.2.4", - "tough-cookie": "^4.1.2", - "w3c-xmlserializer": "^4.0.0", - "webidl-conversions": "^7.0.0", - "whatwg-encoding": "^2.0.0", - "whatwg-mimetype": "^3.0.0", - "whatwg-url": "^12.0.1", - "ws": "^8.13.0", - "xml-name-validator": "^4.0.0" - }, - "engines": { - "node": ">=16" - }, - "peerDependencies": { - "canvas": "^2.5.0" - }, - "peerDependenciesMeta": { - "canvas": { - "optional": true - } - } - }, - "node_modules/jsdom/node_modules/punycode": { - "version": "2.3.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, - "node_modules/jsdom/node_modules/tough-cookie": { - "version": "4.1.2", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "psl": "^1.1.33", - "punycode": "^2.1.1", - "universalify": "^0.2.0", - "url-parse": "^1.5.3" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/jsdom/node_modules/universalify": { - "version": "0.2.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 4.0.0" - } - }, "node_modules/jsesc": { "version": "2.5.2", "dev": true, @@ -19863,11 +19780,6 @@ "node": ">=8" } }, - "node_modules/rrweb-cssom": { - "version": "0.6.0", - "dev": true, - "license": "MIT" - }, "node_modules/run-parallel": { "version": "1.2.0", "dev": true, @@ -21993,25 +21905,6 @@ "node": ">=6" } }, - "node_modules/tr46": { - "version": "4.1.1", - "dev": true, - "license": "MIT", - "dependencies": { - "punycode": "^2.3.0" - }, - "engines": { - "node": ">=14" - } - }, - "node_modules/tr46/node_modules/punycode": { - "version": "2.3.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/tributejs": { "version": "5.1.3", "license": "MIT" @@ -22041,6 +21934,97 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/ts-jest": { + "version": "29.1.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.0.tgz", + "integrity": "sha512-ZhNr7Z4PcYa+JjMl62ir+zPiNJfXJN6E8hSLnaUKhOgqcn8vb3e537cpkd0FuAfRK3sR1LSqM1MOhliXNgOFPA==", + "dev": true, + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "7.x", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^29.0.0", + "babel-jest": "^29.0.0", + "jest": "^29.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, + "node_modules/ts-jest/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.5.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.2.tgz", + "integrity": "sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/ts-jest/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/ts-loader": { "version": "9.4.2", "dev": true, @@ -23914,18 +23898,6 @@ "node": ">=12" } }, - "node_modules/whatwg-url": { - "version": "12.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "tr46": "^4.1.1", - "webidl-conversions": "^7.0.0" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/which": { "version": "2.0.2", "dev": true, @@ -29016,6 +28988,15 @@ } } }, + "bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "requires": { + "fast-json-stable-stringify": "2.x" + } + }, "bser": { "version": "2.1.1", "dev": true, @@ -29766,13 +29747,6 @@ "version": "0.5.0", "dev": true }, - "cssstyle": { - "version": "3.0.0", - "dev": true, - "requires": { - "rrweb-cssom": "^0.6.0" - } - }, "csstype": { "version": "3.1.2" }, @@ -29933,15 +29907,6 @@ "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", "optional": true }, - "data-urls": { - "version": "4.0.0", - "dev": true, - "requires": { - "abab": "^2.0.6", - "whatwg-mimetype": "^3.0.0", - "whatwg-url": "^12.0.0" - } - }, "date-format": { "version": "4.0.14", "dev": true @@ -34346,55 +34311,6 @@ "dev": true, "peer": true }, - "jsdom": { - "version": "22.0.0", - "dev": true, - "requires": { - "abab": "^2.0.6", - "cssstyle": "^3.0.0", - "data-urls": "^4.0.0", - "decimal.js": "^10.4.3", - "domexception": "^4.0.0", - "form-data": "^4.0.0", - "html-encoding-sniffer": "^3.0.0", - "http-proxy-agent": "^5.0.0", - "https-proxy-agent": "^5.0.1", - "is-potential-custom-element-name": "^1.0.1", - "nwsapi": "^2.2.4", - "parse5": "^7.1.2", - "rrweb-cssom": "^0.6.0", - "saxes": "^6.0.0", - "symbol-tree": "^3.2.4", - "tough-cookie": "^4.1.2", - "w3c-xmlserializer": "^4.0.0", - "webidl-conversions": "^7.0.0", - "whatwg-encoding": "^2.0.0", - "whatwg-mimetype": "^3.0.0", - "whatwg-url": "^12.0.1", - "ws": "^8.13.0", - "xml-name-validator": "^4.0.0" - }, - "dependencies": { - "punycode": { - "version": "2.3.0", - "dev": true - }, - "tough-cookie": { - "version": "4.1.2", - "dev": true, - "requires": { - "psl": "^1.1.33", - "punycode": "^2.1.1", - "universalify": "^0.2.0", - "url-parse": "^1.5.3" - } - }, - "universalify": { - "version": "0.2.0", - "dev": true - } - } - }, "jsesc": { "version": "2.5.2", "dev": true @@ -37253,10 +37169,6 @@ } } }, - "rrweb-cssom": { - "version": "0.6.0", - "dev": true - }, "run-parallel": { "version": "1.2.0", "dev": true, @@ -38647,19 +38559,6 @@ } } }, - "tr46": { - "version": "4.1.1", - "dev": true, - "requires": { - "punycode": "^2.3.0" - }, - "dependencies": { - "punycode": { - "version": "2.3.0", - "dev": true - } - } - }, "tributejs": { "version": "5.1.3" }, @@ -38674,6 +38573,60 @@ "trough": { "version": "2.1.0" }, + "ts-jest": { + "version": "29.1.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.0.tgz", + "integrity": "sha512-ZhNr7Z4PcYa+JjMl62ir+zPiNJfXJN6E8hSLnaUKhOgqcn8vb3e537cpkd0FuAfRK3sR1LSqM1MOhliXNgOFPA==", + "dev": true, + "requires": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "7.x", + "yargs-parser": "^21.0.1" + }, + "dependencies": { + "lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.5.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.2.tgz", + "integrity": "sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true + } + } + }, "ts-loader": { "version": "9.4.2", "dev": true, @@ -39873,14 +39826,6 @@ "version": "3.0.0", "dev": true }, - "whatwg-url": { - "version": "12.0.1", - "dev": true, - "requires": { - "tr46": "^4.1.1", - "webidl-conversions": "^7.0.0" - } - }, "which": { "version": "2.0.2", "dev": true, diff --git a/package.json b/package.json index e96e0fba95c..5f729f0fddf 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,6 @@ "jest": "^29.0.3", "jest-environment-jsdom": "^29.5.0", "jsdoc": "^4.0.2", - "jsdom": "^22.0.0", "karma": "^6.4.2", "karma-chrome-launcher": "^3.1.1", "karma-coverage": "2.2.0", @@ -169,6 +168,7 @@ "sinon": "<= 5.0.7", "style-loader": "^3.3.1", "tar": "^6.1.15", + "ts-jest": "^29.1.0", "ts-loader": "^9.4.2", "ts-node": "^10.9.1", "tslib": "^2.5.3", -- 2.39.5