aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-06-14 10:49:40 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-06-21 09:08:04 +0200
commitf8e697ce4dd28ba8899adacf2fa12e33f60b2194 (patch)
tree98951ba5640964212ec4350170a38cb83358a951
parent8b5ef98495597c11caba2ac1fea0416345ec2f0e (diff)
downloadnextcloud-server-f8e697ce4dd28ba8899adacf2fa12e33f60b2194.tar.gz
nextcloud-server-f8e697ce4dd28ba8899adacf2fa12e33f60b2194.zip
feat: prepare jest upgrade and ts testing
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
-rw-r--r--__mocks__/@nextcloud/auth.js15
-rw-r--r--__mocks__/svg.js1
-rw-r--r--__tests__/jest-setup.ts (renamed from tests/jestSetup.js)0
-rw-r--r--custom.d.ts5
-rw-r--r--jest.config.ts (renamed from jest.config.js)42
-rw-r--r--package-lock.json389
-rw-r--r--package.json2
7 files changed, 215 insertions, 239 deletions
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
index c0813ff003f..c0813ff003f 100644
--- a/tests/jestSetup.js
+++ b/__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
index 054ea7184d1..37432033242 100644
--- a/jest.config.js
+++ b/jest.config.ts
@@ -1,4 +1,4 @@
-/*
+/**
* @copyright Copyright (c) 2020 Marco Ambrosini <marcoambrosini@pm.me>
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
@@ -19,42 +19,52 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+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: ['<rootDir>/apps/*/src/**/*.(spec|test).(ts|js)'],
- modulePathIgnorePatterns: ["<rootDir>/apps-extra/"],
+const config: Config = {
+ testMatch: ['<rootDir>/**/*.(spec|test).(ts|js)'],
+ modulePathIgnorePatterns: [
+ '<rootDir>/apps2/',
+ '<rootDir>/apps-extra/',
+ ],
transformIgnorePatterns: [
'node_modules/(?!(' + ignorePatterns.join('|') + ')/)',
],
- setupFilesAfterEnv: ['<rootDir>/tests/jestSetup.js'],
- resetMocks: false,
+ clearMocks: true,
collectCoverageFrom: [
- '<rootDir>/apps/*/src/**/*.{js,vue}',
+ '<rootDir>/**/*.{js,vue}',
],
+ setupFilesAfterEnv: ['<rootDir>/__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', '<rootDir>/'],
+ moduleNameMapper: {
+ '^.+\\.svg(\\?raw)?$': '<rootDir>/__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",