From 7c7d1837343c0b48ad14e4612b4b64ced48e7acd Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Sep 2023 17:22:05 +0200 Subject: [PATCH 1/6] Use vitest globals --- .eslintrc.yaml | 3 +++ vitest.config.js | 1 + web_src/js/features/common-issue-list.test.js | 1 - web_src/js/features/repo-code.test.js | 1 - web_src/js/features/repo-findfile.test.js | 1 - web_src/js/modules/fetch.test.js | 1 - web_src/js/modules/toast.test.js | 1 - web_src/js/render/ansi.test.js | 1 - web_src/js/svg.test.js | 1 - web_src/js/utils.test.js | 1 - web_src/js/utils/color.test.js | 1 - web_src/js/utils/match.test.js | 1 - web_src/js/utils/url.test.js | 1 - 13 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 846823abc7744..77073102b7448 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -46,6 +46,9 @@ overrides: - files: ["*.config.*"] rules: import/no-unused-modules: [0] + - files: ["**/*.test.*"] + env: + jest: true rules: "@eslint-community/eslint-comments/disable-enable-pair": [2] diff --git a/vitest.config.js b/vitest.config.js index 49f59ba982869..9a6cb4e5606fc 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -11,6 +11,7 @@ export default defineConfig({ open: false, allowOnly: true, passWithNoTests: true, + globals: true, watch: false, }, plugins: [ diff --git a/web_src/js/features/common-issue-list.test.js b/web_src/js/features/common-issue-list.test.js index 271acc718aab9..da7ea64b7ca58 100644 --- a/web_src/js/features/common-issue-list.test.js +++ b/web_src/js/features/common-issue-list.test.js @@ -1,4 +1,3 @@ -import {test, expect} from 'vitest'; import {parseIssueListQuickGotoLink} from './common-issue-list.js'; test('parseIssueListQuickGotoLink', () => { diff --git a/web_src/js/features/repo-code.test.js b/web_src/js/features/repo-code.test.js index 3bd1973c1f217..0e0062a787f5d 100644 --- a/web_src/js/features/repo-code.test.js +++ b/web_src/js/features/repo-code.test.js @@ -1,4 +1,3 @@ -import {test, expect} from 'vitest'; import {singleAnchorRegex, rangeAnchorRegex} from './repo-code.js'; test('singleAnchorRegex', () => { diff --git a/web_src/js/features/repo-findfile.test.js b/web_src/js/features/repo-findfile.test.js index a90b0bf0a2cab..2d96ed4463ee1 100644 --- a/web_src/js/features/repo-findfile.test.js +++ b/web_src/js/features/repo-findfile.test.js @@ -1,4 +1,3 @@ -import {describe, expect, test} from 'vitest'; import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted} from './repo-findfile.js'; describe('Repo Find Files', () => { diff --git a/web_src/js/modules/fetch.test.js b/web_src/js/modules/fetch.test.js index ec0377b4d90c4..e4bec3ced9d8b 100644 --- a/web_src/js/modules/fetch.test.js +++ b/web_src/js/modules/fetch.test.js @@ -1,4 +1,3 @@ -import {test, expect} from 'vitest'; import {GET, POST, PATCH, PUT, DELETE} from './fetch.js'; // tests here are only to satisfy the linter for unused functions diff --git a/web_src/js/modules/toast.test.js b/web_src/js/modules/toast.test.js index b5066df0b2889..357f18dbcd61a 100644 --- a/web_src/js/modules/toast.test.js +++ b/web_src/js/modules/toast.test.js @@ -1,4 +1,3 @@ -import {test, expect} from 'vitest'; import {showInfoToast, showErrorToast, showWarningToast} from './toast.js'; test('showInfoToast', async () => { diff --git a/web_src/js/render/ansi.test.js b/web_src/js/render/ansi.test.js index b4793251df58f..5afff71c29f9a 100644 --- a/web_src/js/render/ansi.test.js +++ b/web_src/js/render/ansi.test.js @@ -1,4 +1,3 @@ -import {expect, test} from 'vitest'; import {renderAnsi} from './ansi.js'; test('renderAnsi', () => { diff --git a/web_src/js/svg.test.js b/web_src/js/svg.test.js index 5db2f65ac8d68..06b320c860f00 100644 --- a/web_src/js/svg.test.js +++ b/web_src/js/svg.test.js @@ -1,4 +1,3 @@ -import {expect, test} from 'vitest'; import {svg, SvgIcon, svgParseOuterInner} from './svg.js'; import {createApp, h} from 'vue'; diff --git a/web_src/js/utils.test.js b/web_src/js/utils.test.js index db9b1a14a342f..2754e41c433ec 100644 --- a/web_src/js/utils.test.js +++ b/web_src/js/utils.test.js @@ -1,4 +1,3 @@ -import {expect, test} from 'vitest'; import { basename, extname, isObject, stripTags, parseIssueHref, parseUrl, translateMonth, translateDay, blobToDataURI, diff --git a/web_src/js/utils/color.test.js b/web_src/js/utils/color.test.js index 7d45d191a0919..e129109ef0429 100644 --- a/web_src/js/utils/color.test.js +++ b/web_src/js/utils/color.test.js @@ -1,4 +1,3 @@ -import {test, expect} from 'vitest'; import {useLightTextOnBackground} from './color.js'; test('useLightTextOnBackground', () => { diff --git a/web_src/js/utils/match.test.js b/web_src/js/utils/match.test.js index 5dfbd932f415d..1e30b451d4795 100644 --- a/web_src/js/utils/match.test.js +++ b/web_src/js/utils/match.test.js @@ -1,4 +1,3 @@ -import {test, expect} from 'vitest'; import {matchEmoji, matchMention} from './match.js'; test('matchEmoji', () => { diff --git a/web_src/js/utils/url.test.js b/web_src/js/utils/url.test.js index ef2ffaa5f9963..3dbedec94f1e0 100644 --- a/web_src/js/utils/url.test.js +++ b/web_src/js/utils/url.test.js @@ -1,4 +1,3 @@ -import {expect, test} from 'vitest'; import {pathEscapeSegments} from './url.js'; test('pathEscapeSegments', () => { From 1b129084cb22cb59caed71b5be77bb7a88042696 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Sep 2023 17:26:14 +0200 Subject: [PATCH 2/6] add tsconfig.json --- tsconfig.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000000..aa0a8c03107c8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "types": ["vitest/globals"] + } +} From f1f5401ed28cc8824af5ae1ec5d22e2bde4d7f2e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Sep 2023 17:35:15 +0200 Subject: [PATCH 3/6] remove tsconfig.json --- tsconfig.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index aa0a8c03107c8..0000000000000 --- a/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "types": ["vitest/globals"] - } -} From f2e4ff3840812e18acc58cc5049957f06a861cf1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Sep 2023 18:32:23 +0200 Subject: [PATCH 4/6] use eslint-plugin-vitest-globals instead of jest env --- .eslintrc.yaml | 2 +- package-lock.json | 7 +++++++ package.json | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 77073102b7448..d68c4bcbbc83d 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -48,7 +48,7 @@ overrides: import/no-unused-modules: [0] - files: ["**/*.test.*"] env: - jest: true + vitest-globals/env: true rules: "@eslint-community/eslint-comments/disable-enable-pair": [2] diff --git a/package-lock.json b/package-lock.json index 028f1e24abb90..c710e64396e66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,6 +68,7 @@ "eslint-plugin-regexp": "1.15.0", "eslint-plugin-sonarjs": "0.21.0", "eslint-plugin-unicorn": "48.0.1", + "eslint-plugin-vitest-globals": "1.4.0", "eslint-plugin-vue": "9.17.0", "eslint-plugin-vue-scoped-css": "2.5.0", "eslint-plugin-wc": "1.5.0", @@ -4948,6 +4949,12 @@ "eslint": ">=8.44.0" } }, + "node_modules/eslint-plugin-vitest-globals": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-vitest-globals/-/eslint-plugin-vitest-globals-1.4.0.tgz", + "integrity": "sha512-WE+YlK9X9s4vf5EaYRU0Scw7WItDZStm+PapFSYlg2ABNtaQ4zIG7wEqpoUB3SlfM+SgkhgmzR0TeJOO5k3/Nw==", + "dev": true + }, "node_modules/eslint-plugin-vue": { "version": "9.17.0", "resolved": "https://registry.npmjs.org/eslint-plugin-vue/-/eslint-plugin-vue-9.17.0.tgz", diff --git a/package.json b/package.json index 87182ab214472..b57258804bd73 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "eslint-plugin-regexp": "1.15.0", "eslint-plugin-sonarjs": "0.21.0", "eslint-plugin-unicorn": "48.0.1", + "eslint-plugin-vitest-globals": "1.4.0", "eslint-plugin-vue": "9.17.0", "eslint-plugin-vue-scoped-css": "2.5.0", "eslint-plugin-wc": "1.5.0", From 14652e9c6f844dd4cd66abeec1b657d7ee8819d3 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Sep 2023 18:35:18 +0200 Subject: [PATCH 5/6] add to plugins --- .eslintrc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index d68c4bcbbc83d..5439f07883b62 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -19,6 +19,7 @@ plugins: - eslint-plugin-regexp - eslint-plugin-sonarjs - eslint-plugin-unicorn + - eslint-plugin-vitest-globals - eslint-plugin-wc env: From e57bc475aca971517bb02eb89051d32b79b8545b Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 18 Sep 2023 01:08:49 +0200 Subject: [PATCH 6/6] globals are available in web_src/js/test/setup.js as well --- .eslintrc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 5439f07883b62..5461bf1be63dc 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -47,7 +47,7 @@ overrides: - files: ["*.config.*"] rules: import/no-unused-modules: [0] - - files: ["**/*.test.*"] + - files: ["**/*.test.*", "web_src/js/test/setup.js"] env: vitest-globals/env: true