-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
frontend: use vite's mechanism for env variables to fill window.envir… #3268
frontend: use vite's mechanism for env variables to fill window.envir… #3268
Conversation
fac673c
to
7a7d916
Compare
⛔ Feature branch deployment currently inactive.If the PR is still open, you can add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have a environment.js
file in the .jest
folder: https://github.com/ecamp/ecamp3/blob/devel/frontend/.jest/environment.js
This is still needed and properly used, right?
Sadly we still use vue-cli to run our tests, so there the vite mechanism does not work and we have to maintain one additional environment.js. |
Migrating from jest / vue-cli to vitest shouldn't be too hard. Maybe I'll try that soon |
7397544
to
b9b475d
Compare
I tried it. They kept the api from jest, but there is not e a drop in replacement for everything. https://github.com/BacLuc/ecamp3/tree/try-vitest |
I've gotten a lot further in the vitest migration, and am still actively working on this. Just FYI, so we don't do too much parallel work. |
Should i
|
My work on top of yours is now here: https://github.com/carlobeltrame/ecamp3/tree/try-vitest |
af943ea
to
db0e26d
Compare
@@ -39,134 +41,133 @@ ruleTester.run('local-rules/matching-translation-keys', ruleInstance, { | |||
name: 'allows correct key in js', | |||
code: '$tc("components.hello.world")', | |||
options: options, | |||
filename: '/app/src/components/hello.js', | |||
filename: '/src/components/hello.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not get the packageDirectory mock to work, so i used a simple solution.
Else it works in the docker container, but not when run locally with an interpreter.
ok @carlobeltrame ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the tests work in CI and when run in the way we have it documented in the wiki, fine by me
frontend/package.json
Outdated
"collectCoverageFrom": [ | ||
"src/**/*.{js,vue}", | ||
"common/**/*.js", | ||
"!src/components/print/print-react/generatePdf.js" | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to use this config also for the v8 coverage.
Should i do this in this PR, or can we do this in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would merge this and then see whether we have any coverage problems, and solve those later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not get these tests to run.
commit message:
frontend: delete RichText tests
Because i could not get them to run with vitest.
The error i could not resolve:
FAIL src/components/form/api/tests/ApiRichtext.spec.js > An ApiRichtext > updates state if value in store is refreshed and has new value
TypeError: tippy is not a function
❯ BubbleMenuView.createTooltip node_modules/@tiptap/extension-bubble-menu/src/bubble-menu-plugin.ts:141:18
❯ BubbleMenuView.updateHandler node_modules/@tiptap/extension-bubble-menu/src/bubble-menu-plugin.ts:200:10
❯ BubbleMenuView.update node_modules/@tiptap/extension-bubble-menu/src/bubble-menu-plugin.ts:170:10
❯ EditorView.updatePluginViews node_modules/prosemirror-view/dist/index.js:5262:32
❯ EditorView.updateStateInner node_modules/prosemirror-view/dist/index.js:5211:14
❯ EditorView.updateState node_modules/prosemirror-view/dist/index.js:5142:14
❯ Editor.dispatchTransaction node_modules/@tiptap/core/src/Editor.ts:344:15
❯ EditorView.dispatch node_modules/prosemirror-view/dist/index.js:5471:33
❯ Object.method [as setContent] node_modules/@tiptap/core/src/CommandManager.ts:42:18
❯ VueComponent.value src/components/form/tiptap/TiptapEditor.vue:174:1
172| // of the input field
173| if (val !== this.html) {
174| this.editor.commands.setContent(val)
| ^
175| }
176| },
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let's write new ones later.
@@ -1,63 +1,45 @@ | |||
// Libraries | |||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here i had problems with the virtualTIme.
It did not work as expected, so i used additional promises and resolvers to control the execution of promises.
frontend/src/plugins/store/index.js
Outdated
@@ -41,4 +42,6 @@ class StorePlugin { | |||
export let apiStore | |||
export let store | |||
|
|||
export let storePlugin = new StorePlugin() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for the auth.spec.js test.
As soon as i started mocking the router, store.replaceState was undefined...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was able to simplify this: b33f67e
} | ||
} | ||
|
||
function createStubs() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here i had to change the stups to CamelCase
@@ -39,134 +41,133 @@ ruleTester.run('local-rules/matching-translation-keys', ruleInstance, { | |||
name: 'allows correct key in js', | |||
code: '$tc("components.hello.world")', | |||
options: options, | |||
filename: '/app/src/components/hello.js', | |||
filename: '/src/components/hello.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the tests work in CI and when run in the way we have it documented in the wiki, fine by me
frontend/package.json
Outdated
"collectCoverageFrom": [ | ||
"src/**/*.{js,vue}", | ||
"common/**/*.js", | ||
"!src/components/print/print-react/generatePdf.js" | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would merge this and then see whether we have any coverage problems, and solve those later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let's write new ones later.
set: lodash.set, | ||
get: lodash.get, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That shouldn't be necessary after the ...lodash
above..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i also expected that, but it did not work without setting these to explicitly.
Did you test it and it worked?
const lodash = await importOriginal() | ||
return { | ||
...lodash, | ||
debounce: (callback) => new Promise((resolve) => (debounce = resolve)).then(callback), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very funky... This implementation only supports one debounce at a time, because there is only one global let debounce
, right? But I guess it is fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but why would you have 2 debounce before a user interaction/web request/response...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to write a test where e.g. the user triggers two separate debounced buttons, and check whether everything is executed in the expected order. I think this kind of setup is not supported by this mock.
frontend/src/plugins/store/index.js
Outdated
@@ -41,4 +42,6 @@ class StorePlugin { | |||
export let apiStore | |||
export let store | |||
|
|||
export let storePlugin = new StorePlugin() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was able to simplify this: b33f67e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked on my machine ;)
Not all tests are running
Because vitest cannot resolve the files if there is no extension. And update snapshots.
Vitest said correctly that this method does not exist.
Let the test helpers create the store, just provide a json. This fixes Error: [vuex] getters should be function but "getters.getLoggedInUser" is {"_meta":{"self":"/users/17d341a80579"}}. Write the stubs in camel case And simplify a little.
Because i could not get them to run with vitest. The error i could not resolve: FAIL src/components/form/api/__tests__/ApiRichtext.spec.js > An ApiRichtext > updates state if value in store is refreshed and has new value TypeError: tippy is not a function ❯ BubbleMenuView.createTooltip node_modules/@tiptap/extension-bubble-menu/src/bubble-menu-plugin.ts:141:18 ❯ BubbleMenuView.updateHandler node_modules/@tiptap/extension-bubble-menu/src/bubble-menu-plugin.ts:200:10 ❯ BubbleMenuView.update node_modules/@tiptap/extension-bubble-menu/src/bubble-menu-plugin.ts:170:10 ❯ EditorView.updatePluginViews node_modules/prosemirror-view/dist/index.js:5262:32 ❯ EditorView.updateStateInner node_modules/prosemirror-view/dist/index.js:5211:14 ❯ EditorView.updateState node_modules/prosemirror-view/dist/index.js:5142:14 ❯ Editor.dispatchTransaction node_modules/@tiptap/core/src/Editor.ts:344:15 ❯ EditorView.dispatch node_modules/prosemirror-view/dist/index.js:5471:33 ❯ Object.method [as setContent] node_modules/@tiptap/core/src/CommandManager.ts:42:18 ❯ VueComponent.value src/components/form/tiptap/TiptapEditor.vue:174:1 172| // of the input field 173| if (val !== this.html) { 174| this.editor.commands.setContent(val) | ^ 175| } 176| },
router.push takes ca 2 seconds, which is too long for a unit tests. Thus we mock router.push and router.resolve. Then store.replace does not work anymore, thus we use vi.importActual to make sure not the somehow mocked store is used.
…t for vitest Mocking seems a little difficult with vitest. If we keep the /app, the tests work in the docker container, but not when running the tests with a local interpreter.
…onment That we don't have locally cached environment.js files breaking the development setup. Sadly we still use vue-cli to run our tests, so there the vite mechanism does not work and we have to maintain one additional environment.js. In production, we compose the environment.js anyway in the configmap, thus we don't have to consider the production case in dev-environment.js. Now we can also remove the check in index.html. In a production environment, you have to check yourself that you have all the needed configurations set. closes ecamp#3267
c9193ee
to
bb570c7
Compare
…onment
That we don't have locally cached environment.js files breaking the development setup. Sadly we still use vue-cli to run our tests, so there the vite mechanism does not work and we have to maintain one additional environment.js.
In production, we compose the environment.js anyway in the configmap, thus we don't have to consider the production case in dev-environment.js.
Now we can also remove the check in index.html.
In a production environment, you have to check yourself that you have all the needed configurations set.
closes #3267
EDIT:
Current state: could not get the tests to run... -> converted it to draft againEDIT:
Now turned the PR around:
Step 1:
replace jest with vitest
See the single commits for some quirky fixes that it works.
Also reduces the coverage by 6% in the frontend, and the overall coverage by 30%
Step 2:
Use the vite env variable mechanism to fill environmnet
I will use review comments in the files that we can discuss the different fixes that were needed.