Skip to content

Commit

Permalink
use playwright for e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbbx committed Nov 5, 2024
1 parent f021198 commit 8da6d86
Show file tree
Hide file tree
Showing 82 changed files with 2,003 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5504
}
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "3d-tile-content-inspector",
"version": "1.0.0",
"description": "[3D tile content](https://github.com/CesiumGS/3d-tiles/blob/master/specification/README.md#tile-format-specifications) inspector.",
"main": "index.js",
"directories": {
"doc": "docs"
},
"scripts": {
"test": "npx playwright install && npx playwright test && npx playwright show-report"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.48.2",
"@types/node": "^22.9.0"
}
}
79 changes: 79 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});

2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="ui-container">
Load tile content(<code>.pnts</code>, <code>.b3dm</code>, <code>.i3dm</code>, <code>.cmpt</code>), <code>.glb</code> or <code>draco</code> file from:
<ol>
<li><label for="url">URL(https only): </label><input type="url" id="url" /> then <button id="inspect">inspect</button> it</li>
<li><del><label for="url">URL(https only): </label><input disabled type="url" id="url" /> then <button id="inspect"><del>inspect</del></button> it</del></li>
<li>local file system, <label for="file"><strong>choose a file</strong></label> <input hidden="true" type="file" id="file" accept=".pnts, .b3dm, .i3dm, .cmpt, .glb, .drc" />,</li>
<li>drag it on window anywhere.</li>
</ol>
Expand Down
6 changes: 4 additions & 2 deletions src/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function inspectDraco(arrayBuffer) {
const bufferView = {
byteLength: arrayBuffer.byteLength,
};
const decodedDraco = decodePrimitive(arrayBuffer, bufferView, undefined, true);
const decodedDraco = decodePrimitive(new Uint8Array(arrayBuffer), bufferView, undefined, true);
const attributeData = decodedDraco.attributeData;

for (const attributeId in attributeData) {
Expand All @@ -109,7 +109,9 @@ function inspectDraco(arrayBuffer) {
attribute.array = attribute.array.slice(0, 100);
}
}
decodedDraco.indexArray.typedArray = decodedDraco.indexArray.typedArray.slice(0, 100);
if (decodedDraco.indexArray) {
decodedDraco.indexArray.typedArray = decodedDraco.indexArray.typedArray?.slice(0, 100);
}

return decodedDraco;
}
Expand Down
28 changes: 26 additions & 2 deletions src/parseDraco.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ function decodePrimitive(typedArray, bufferView, compressedAttributes, useDefaul
// Decode the encoded geometry.
let dracoGeometry;
let status;
if (geometryType == decoderModule.TRIANGULAR_MESH) {
if (geometryType === decoderModule.TRIANGULAR_MESH) {
dracoGeometry = new decoderModule.Mesh();
status = decoder.DecodeBufferToMesh(buffer, dracoGeometry);
} else {
} else if (geometryType === decoderModule.POINT_CLOUD) {
dracoGeometry = new decoderModule.PointCloud();
status = decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
} else {
throw new Error(`unknown Draco geometry type: ${geometryType}.`);
}

if (!status.ok() || dracoGeometry.ptr === 0) {
Expand Down Expand Up @@ -165,6 +167,7 @@ function decodePrimitive(typedArray, bufferView, compressedAttributes, useDefaul
}

const result = {
geometryType: geometryType === decoderModule.TRIANGULAR_MESH ? 'TRIANGULAR_MESH' : 'POINT_CLOUD',
attributeData: attributeData,
indexArray: undefined,
};
Expand All @@ -176,6 +179,27 @@ function decodePrimitive(typedArray, bufferView, compressedAttributes, useDefaul
decoderModule.destroy(dracoGeometry);
decoderModule.destroy(decoder);

const loggedResult = {
geometryType: result.geometryType,
attributeData: {},
};
for (const attributeName in result.attributeData) {
if (Object.prototype.hasOwnProperty.call(result.attributeData, attributeName)) {
const attribute = result.attributeData[attributeName];
loggedResult.attributeData[attributeName] = {
array: attribute.array,
data: attribute.data,
};
}
}
if (result.indexArray) {
loggedResult.indexArray = {
numberOfIndices: result.indexArray.numberOfIndices,
typedArray: result.indexArray.typedArray,
};
}
console.log(`draco primitive:`, loggedResult);

return result;
}

Expand Down
Loading

0 comments on commit 8da6d86

Please sign in to comment.