Skip to content
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

fix(helper): test setup mimics sandbox environment #341

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
"dev:vue3": "yarn dev:template vue3",
"test:template": "yarn workspace field-plugin-${0}-template test --config node_modules/.${0}-vite.config.ts --ui",
"test:react": "yarn test:template react",
"test:js": "yarn test:template js",
"test:vue2": "yarn test:template vue2",
"test:vue3": "yarn test:template vue3",
"bump-version": "./scripts/bump-version.ts"
},
Expand Down
9 changes: 8 additions & 1 deletion packages/field-plugin/helpers/test/src/index.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried changing the location to the sandbox url inside the location stub but sadly I could not make it work.

  vi.stubGlobal('location', {
    ...window.location,
    search: `?protocol=https%3A&host=plugin-sandbox.storyblok.com&uid=test-uid&preview=1`,
  })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the current update seems good :)

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {

import { vi } from 'vitest'

const sandboxOrigin: string = 'https://plugin-sandbox.storyblok.com'

const getContainer = (sendToFieldPlugin: (data: unknown) => void) => {
const schema = {
field_type: 'test-field-plugin',
Expand Down Expand Up @@ -110,15 +112,20 @@ export const setupFieldPlugin = () => {
let handleEvent: (event: MessageEvent<unknown>) => void
const container = getContainer((data: unknown) => {
// @ts-ignore
handleEvent({ data })
handleEvent({
data,
origin: sandboxOrigin,
})
})
global.ResizeObserver = class ResizeObserver {
observe() {
// do nothing
}

unobserve() {
// do nothing
}

disconnect() {
// do nothing
}
Expand Down
Loading