Skip to content

Commit

Permalink
Merge branch 'main' into SHAPE-7009-allow-other-origins-in-field-plug…
Browse files Browse the repository at this point in the history
…in-sdk
  • Loading branch information
demetriusfeijoo authored Sep 20, 2024
2 parents 27a4dbe + 39e0c4a commit 1ce828d
Show file tree
Hide file tree
Showing 15 changed files with 1,396 additions and 2,069 deletions.
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,17 @@
},
"devDependencies": {
"@storyblok/mui": "0.2.0",
"@types/jest": "29.5.12",
"@types/node": "18.19.17",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "8.56.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-functional": "^4.2.2",
"eslint-plugin-prettier": "^5.1.3",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"kleur": "4.1.5",
"prettier": "^3.2.5",
"prompts": "2.4.2",
"semver": "7.6.0",
"ts-jest": "29.1.2",
"tsx": "3.14.0",
"typescript": "^5.3.3",
"vite": "5.1.3",
Expand Down
4 changes: 0 additions & 4 deletions packages/demo/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"test": "jest",
"check:types": "tsc --noEmit"
},
"dependencies": {
Expand Down
4 changes: 0 additions & 4 deletions packages/field-plugin/jest.config.js

This file was deleted.

16 changes: 7 additions & 9 deletions packages/field-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@
"scripts": {
"check:types": "tsc --noEmit",
"dev": "vite build --watch",
"test": "jest",
"test": "vitest",
"build": "yarn build:manifest-helper && unbuild && yarn build:helpers",
"build:helpers": "cd helpers && unbuild",
"build:manifest-helper": "cd ../manifest-helper && yarn build"
},
"devDependencies": {
"@types/core-js": "2.5.8",
"@types/jest": "29.5.12",
"@types/node": "*",
"@types/node": "18.19.17",
"core-js": "3.36.0",
"execa": "8.0.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"ts-jest": "29.1.2",
"typescript": "*",
"jsdom": "25.0.0",
"typescript": "^5.3.3",
"unbuild": "2.0.0",
"vite": "*",
"vite-plugin-dts": "*"
"vite": "5.4.6",
"vite-plugin-dts": "4.2.1",
"vitest": "2.1.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { createHeightChangeListener } from './createHeightChangeListener'

describe('auto resizer', () => {
it('observes the document body', () => {
const onHeightChange = jest.fn()
const onHeightChange = vi.fn()
const { observe } = mockResizeObserver()
expect(observe).not.toHaveBeenCalledWith(document.body)
createHeightChangeListener(onHeightChange)
expect(observe).toHaveBeenCalledWith(document.body)
})
it('disconnects when the cleanup function is called', () => {
const { mockResize } = mockResizeObserver()
const onHeightChange = jest.fn()
const onHeightChange = vi.fn()
const cleanup = createHeightChangeListener(onHeightChange)
expect(onHeightChange).toHaveBeenCalledTimes(0)
mockResize()
Expand All @@ -23,7 +23,7 @@ describe('auto resizer', () => {
})
it('post to container the correct number of times', () => {
const { mockResize } = mockResizeObserver()
const onHeightChange = jest.fn()
const onHeightChange = vi.fn()
mockResize()
expect(onHeightChange).toHaveBeenCalledTimes(0)
createHeightChangeListener(onHeightChange)
Expand All @@ -35,43 +35,41 @@ describe('auto resizer', () => {
})
it('calls the callback function', () => {
const { mockResize } = mockResizeObserver()
const onHeightChange = jest.fn()
const onHeightChange = vi.fn()
createHeightChangeListener(onHeightChange)
mockResize()
expect(onHeightChange).toHaveBeenCalled()
})
it('calls the callback function with the height as argument', () => {
const { mockResize } = mockResizeObserver()
const expectedClientHeight = 3816
jest
.spyOn(document.body, 'clientHeight', 'get')
.mockImplementation(() => expectedClientHeight)
const onHeightChange = jest.fn()
vi.spyOn(document.body, 'clientHeight', 'get').mockImplementation(
() => expectedClientHeight,
)
const onHeightChange = vi.fn()
createHeightChangeListener(onHeightChange)
mockResize()
expect(onHeightChange).toHaveBeenCalledWith(expectedClientHeight)
})
})

const mockResizeObserver = () => {
const observe = jest.fn()
const observe = vi.fn()

// eslint-disable-next-line functional/no-let
let mockEvents: (() => void)[] = []
const mockResize = () => mockEvents.forEach((it) => it())

global.ResizeObserver = jest
.fn()
.mockImplementation((onEvent: () => void) => {
mockEvents = [...mockEvents, onEvent]
const disconnect = () => {
mockEvents = mockEvents.filter((it) => it !== onEvent)
}
return {
observe,
disconnect,
}
})
global.ResizeObserver = vi.fn().mockImplementation((onEvent: () => void) => {
mockEvents = [...mockEvents, onEvent]
const disconnect = () => {
mockEvents = mockEvents.filter((it) => it !== onEvent)
}
return {
observe,
disconnect,
}
})

return {
observe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { emptyAsset } from '../../messaging/pluginMessage/containerToPluginMessa

const mock = () => ({
uid: 'abc',
postToContainer: jest.fn(),
onUpdateState: jest.fn(),
postToContainer: vi.fn(),
onUpdateState: vi.fn(),
})

const TEST_CALLBACK_ID = 'test-callback-id'

jest.mock('../../utils/getRandomUid', () => {
vi.mock('../../utils/getRandomUid', () => {
return {
getRandomUid: jest.fn(() => TEST_CALLBACK_ID),
getRandomUid: vi.fn(() => TEST_CALLBACK_ID),
}
})

Expand Down Expand Up @@ -259,8 +259,8 @@ describe('createPluginActions', () => {
filename,
asset: emptyAsset,
})
const resolvedFn = jest.fn()
const rejectedFn = jest.fn()
const resolvedFn = vi.fn()
const rejectedFn = vi.fn()
promise.then(resolvedFn).catch(rejectedFn)
await wait(100)
expect(resolvedFn).toHaveBeenCalledTimes(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { emptyAsset } from '../../../messaging/pluginMessage/containerToPluginMe

const uid = 'abc123'
const mockCallbacks = (): PluginMessageCallbacks => ({
onStateChange: jest.fn(),
onContextRequest: jest.fn(),
onAssetSelect: jest.fn(),
onUnknownMessage: jest.fn(),
onLoaded: jest.fn(),
onStateChange: vi.fn(),
onContextRequest: vi.fn(),
onAssetSelect: vi.fn(),
onUnknownMessage: vi.fn(),
onLoaded: vi.fn(),
})

describe('handlePluginMessage', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/field-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "../../tsconfig.base.json",
// vite-plugin-dts will output at the root level unless specified here
"compilerOptions": {
"types": ["vitest/globals"],
"skipLibCheck": true,
"outDir": "dist"
},
"include": ["src/**/*.ts", "src/**/*.d.ts"],
Expand Down
6 changes: 5 additions & 1 deletion packages/field-plugin/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { defineConfig } from 'vite'
import { defineConfig } from 'vitest/config'
import { fileURLToPath } from 'url'
import dts from 'vite-plugin-dts'

// https://vitejs.dev/config/
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
},
plugins: [
dts({
insertTypesEntry: true,
Expand Down
4 changes: 0 additions & 4 deletions packages/sandbox/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dev": "vite",
"build": "yarn check:types && vite build",
"lint": "eslint .",
"test": "jest",
"check:types": "tsc --noEmit"
},
"dependencies": {
Expand Down
10 changes: 2 additions & 8 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
"useUnknownInCatchVariables": true,
"allowJs": false
},
"exclude": [
"node_modules",
"packages/*/node_modules",
],
"include": [
"**/*.ts",
"**/*.tsx"
]
"exclude": ["node_modules", "packages/*/node_modules"],
"include": ["**/*.ts", "**/*.tsx"]
}
Loading

0 comments on commit 1ce828d

Please sign in to comment.