Skip to content

Commit 7fc7007

Browse files
authored
fix: snapshots on init (#31)
1 parent fb4a261 commit 7fc7007

18 files changed

+401
-109
lines changed
77.9 KB
Loading

integration-tests/index.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import initCreator, { SerializedAsset } from '../src/index'
1+
import initCreator, { SerializedOutputAsset } from '../src/index'
22

33
declare global {
44
interface Window {
5-
assetsSnapshot: SerializedAsset[]
5+
assetsSnapshot: SerializedOutputAsset[]
66
}
77
}
88

9-
const assetsUpdatesHistory: SerializedAsset[][] = [[]]
9+
const assetsUpdatesHistory: SerializedOutputAsset[][] = [[]]
1010

1111
async function test() {
1212
const canvas = document.querySelector<HTMLCanvasElement>('canvas')!
@@ -22,7 +22,6 @@ async function test() {
2222

2323
const creator = await initCreator(
2424
canvas,
25-
[],
2625
(assets) => {
2726
window.assetsSnapshot = assets
2827
// we had to implement this whole history logic because there is no way
@@ -41,17 +40,25 @@ async function test() {
4140
}
4241
)
4342

44-
const fileInput = document.querySelector<HTMLInputElement>('input')!
45-
fileInput.addEventListener('change', (event) => {
43+
const addImageInput = document.querySelector<HTMLInputElement>('#add-image')!
44+
addImageInput.addEventListener('change', (event) => {
4645
const { files } = event.target as HTMLInputElement
4746
if (!files) return
47+
creator.addImage(URL.createObjectURL(files[0]))
48+
addImageInput.value = '' // reset input value to allow re-uploading the same file
49+
})
4850

49-
const img = new Image()
50-
img.src = URL.createObjectURL(files[0])
51-
img.onload = () => {
52-
creator.addImage(img)
53-
}
54-
fileInput.value = '' // reset input value to allow re-uploading the same file
51+
const startProjectInput = document.querySelector<HTMLInputElement>('#start-project-from-images')!
52+
startProjectInput.addEventListener('change', (event) => {
53+
const { files } = event.target as HTMLInputElement
54+
if (!files) return
55+
creator.resetAssets(
56+
Array.from(files).map((file) => ({
57+
url: URL.createObjectURL(file),
58+
})),
59+
true
60+
)
61+
startProjectInput.value = '' // reset input value to allow re-uploading the same file
5562
})
5663

5764
removeAssetBtn.addEventListener('click', () => {

integration-tests/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
6565
const testImagePath = path.join(__dirname, './image-sample.png')
6666

6767
async function uploadAsset() {
68-
const fileInput = (await page.$('input[type="file"]'))!
68+
const fileInput = (await page.$('#add-image'))!
6969
await fileInput.setInputFiles(testImagePath)
7070
const assets = await getAssetsState()
7171
return assets[assets.length - 1] // return the last uploaded asset

integration-tests/template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
<body>
3232
<aside>
33-
<input type="file" />
33+
<label>Add image<input type="file" id="add-image" /></label>
34+
<label>Start project from images<input type="file" multiple id="start-project-from-images" /></label>
3435
<p>Selected asset: <span id="selected-asset-id">0</span></p>
3536
<p>Is processing events: <span id="is-processing-events">false</span></p>
3637
<button id="remove-btn">Remove Asset</button>

integration-tests/tests/history.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ test('asset selection', async ({ page }, testinfo) => {
99
return
1010
}
1111
testinfo.snapshotSuffix = '' // by default is `process.platform`
12-
const undoBtn = page.locator('#undo-btn')!
13-
const redoBtn = page.locator('#redo-btn')!
12+
const undoBtn = page.locator('#undo-btn')
13+
const redoBtn = page.locator('#redo-btn')
1414
const assetIdEl = page.locator('#selected-asset-id')
1515

1616
const utils = await init(page)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// npm run test-e2e -- initial-assets.spec.ts --debug
2+
3+
import { test, expect } from '@playwright/test'
4+
import init from '../init'
5+
import { fileURLToPath } from 'url'
6+
import path from 'path'
7+
8+
test('initial assets', async ({ page }, testinfo) => {
9+
if (process.env.CI) {
10+
test.skip()
11+
return
12+
}
13+
testinfo.snapshotSuffix = '' // by default is `process.platform`
14+
15+
const utils = await init(page)
16+
17+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
18+
const testImagePaths = [
19+
path.join(__dirname, '../image-sample.png'),
20+
path.join(__dirname, '../another-image-sample.jpg'),
21+
]
22+
23+
const fileInput = (await page.$('#start-project-from-images'))!
24+
await fileInput.setInputFiles(testImagePaths)
25+
const assets = await utils.getAssetsState()
26+
expect(assets.length).toBe(2)
27+
})

package-lock.json

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@webgpu/types": "^0.1.54",
3939
"eslint": "^9.28.0",
4040
"html-webpack-plugin": "^5.6.3",
41+
"http-server": "^14.1.1",
4142
"jest": "^29.7.0",
4243
"jest-environment-jsdom": "^29.7.0",
4344
"msdf-bmfont-xml": "^2.7.0",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default defineConfig({
111111
/* Run your local dev server before starting the tests */
112112
// if we deploy something to "staging" like environment, then we can get rid of that webServer local run
113113
webServer: {
114-
command: 'npm run build && npx http-server lib-test -p 9275',
114+
command: 'npm run build && http-server lib-test -p 9275',
115115
url: 'http://127.0.0.1:9275',
116116
reuseExistingServer: !process.env.CI,
117117
},

src/WebGPU/pick.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export default class PickManager {
112112

113113
let i = 0
114114
while (i < pointer.afterPickEventsQueue.length) {
115+
// this is pretty stupid, because pointer.x, pointer.y were updated immediately
116+
// without waiting for this place right here
115117
const { requireNewPick, cb } = pointer.afterPickEventsQueue[i]
116118
if (requireNewPick && i > 0) break // we need to start new picking pass
117119
cb()

0 commit comments

Comments
 (0)