Skip to content
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
3 changes: 3 additions & 0 deletions packages/playground/blueprints/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Blueprints require WordPress Playground's Node polyfills.
import '@php-wasm/node-polyfills';

export * from './lib/steps';
export * from './lib/steps/handlers';
export { runBlueprintSteps, compileBlueprint } from './lib/compile';
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/blueprints/src/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '@php-wasm/progress';
import { UniversalPHP } from '@php-wasm/universal';
import { Semaphore } from '@php-wasm/util';
import { File, zipNameToHumanName } from './steps/common';
import { zipNameToHumanName } from './steps/common';

export const ResourceTypes = [
'vfs',
Expand Down
28 changes: 0 additions & 28 deletions packages/playground/blueprints/src/lib/steps/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,6 @@ export async function fileToUint8Array(file: File) {
return new Uint8Array(await file.arrayBuffer());
}

/**
* Polyfill the File class in JSDOM which lacks arrayBuffer() method
*
* - [Implement Blob.stream, Blob.text and Blob.arrayBuffer](https://github.com/jsdom/jsdom/issues/2555)
*
* When a Resource (../resources.ts) resolves to an instance of File, the
* resulting object is missing the arrayBuffer() method in JSDOM environment
* during tests.
*
* Import the polyfilled File class below to ensure its buffer is available to
* functions like writeFile (./client-methods.ts) and fileToUint8Array (above).
*/
class FilePolyfill extends File {
buffers: BlobPart[];
constructor(buffers: BlobPart[], name: string) {
super(buffers, name);
this.buffers = buffers;
}
override async arrayBuffer(): Promise<ArrayBuffer> {
return this.buffers[0] as ArrayBuffer;
}
}

const FileWithArrayBuffer =
File.prototype.arrayBuffer instanceof Function ? File : FilePolyfill;

export { FileWithArrayBuffer as File };

export async function runPhpWithZipFunctions(
playground: UniversalPHP,
code: string
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/blueprints/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export default defineConfig({

test: {
globals: true,
setupFiles: ['./src/vitest-setup-file.ts'],
cache: {
dir: '../../../node_modules/.vitest',
},
setupFiles: ['./src/vitest-setup-file.ts'],
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
Expand Down