Skip to content

Commit

Permalink
Don't rely on node build in wasm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Sep 11, 2023
1 parent fa01e5a commit 4458481
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
5 changes: 3 additions & 2 deletions node/test/bundle.test.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from 'path';
import fs from 'fs';
import { bundleAsync as bundleAsyncNative } from '../index.mjs';
import { test } from 'uvu';
import * as assert from 'uvu/assert';

let bundleAsync = bundleAsyncNative;
let bundleAsync;
if (process.env.TEST_WASM === 'node') {
bundleAsync = (await import('../../wasm/wasm-node.mjs')).bundleAsync;
} else if (process.env.TEST_WASM === 'browser') {
Expand All @@ -20,6 +19,8 @@ if (process.env.TEST_WASM === 'node') {

return wasm.bundleAsync(options);
}
} else {
bundleAsync = (await import('../index.mjs')).bundleAsync;
}

test('resolver', async () => {
Expand Down
9 changes: 5 additions & 4 deletions node/test/composeVisitors.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { transform as transformNative, composeVisitors } from '../index.mjs';

let transform = transformNative;
let transform, composeVisitors;
if (process.env.TEST_WASM === 'node') {
transform = (await import('../../wasm/wasm-node.mjs')).transform;
({transform, composeVisitors} = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
transform = wasm.transform;
({transform, composeVisitors} = wasm);
} else {
({transform, composeVisitors} = await import('../index.mjs'));
}

test('different types', () => {
Expand Down
5 changes: 3 additions & 2 deletions node/test/customAtRules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import { test } from 'uvu';
import * as assert from 'uvu/assert';
import * as native from '../index.mjs';
import fs from 'fs';

let { bundle, transform } = native;
let bundle, transform;
if (process.env.TEST_WASM === 'node') {
({ bundle, transform } = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
Expand All @@ -20,6 +19,8 @@ if (process.env.TEST_WASM === 'node') {
}
});
}
} else {
({bundle, transform} = await import('../index.mjs'));
}

test('declaration list', () => {
Expand Down
9 changes: 5 additions & 4 deletions node/test/transform.test.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { transform as transformNative, Features } from 'lightningcss';
import { test } from 'uvu';
import * as assert from 'uvu/assert';

let transform = transformNative;
let transform, Features;
if (process.env.TEST_WASM === 'node') {
transform = (await import('../../wasm/wasm-node.mjs')).transform;
({transform, Features} = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
transform = wasm.transform;
({transform, Features} = wasm);
} else {
({transform, Features} = await import('../index.mjs'));
}

test('can enable non-standard syntax', () => {
Expand Down
5 changes: 3 additions & 2 deletions node/test/visitor.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import { test } from 'uvu';
import * as assert from 'uvu/assert';
import * as native from '../index.mjs';
import fs from 'fs';

let { bundle, bundleAsync, transform, transformStyleAttribute } = native;
let bundle, bundleAsync, transform, transformStyleAttribute;
if (process.env.TEST_WASM === 'node') {
({ bundle, bundleAsync, transform, transformStyleAttribute } = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
Expand All @@ -31,6 +30,8 @@ if (process.env.TEST_WASM === 'node') {

return wasm.bundleAsync(options);
}
} else {
({ bundle, bundleAsync, transform, transformStyleAttribute } = await import('../index.mjs'));
}

test('px to rem', () => {
Expand Down
4 changes: 4 additions & 0 deletions scripts/build-wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ let flags = fs.readFileSync(`${dir}/node/flags.js`, 'utf8');
flags = flags.replace('exports.Features =', 'export const Features =');
fs.writeFileSync(`${dir}/wasm/flags.js`, flags);

let composeVisitors = fs.readFileSync(`${dir}/node/composeVisitors.js`, 'utf8');
composeVisitors = composeVisitors.replace('module.exports = composeVisitors', 'export { composeVisitors }');
fs.writeFileSync(`${dir}/wasm/composeVisitors.js`, composeVisitors);

let dts = fs.readFileSync(`${dir}/node/index.d.ts`, 'utf8');
dts = dts.replace(/: Buffer/g, ': Uint8Array');
dts += `
Expand Down
1 change: 1 addition & 0 deletions wasm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ package.json
README.md
browserslistToTargets.js
flags.js
composeVisitors.js
5 changes: 3 additions & 2 deletions wasm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export function bundleAsync(options) {
return bundleAsyncInternal(options);
}

export { browserslistToTargets } from './browserslistToTargets.js'
export { Features } from './flags.js'
export { browserslistToTargets } from './browserslistToTargets.js';
export { Features } from './flags.js';
export { composeVisitors } from './composeVisitors.js';

async function load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
Expand Down
1 change: 1 addition & 0 deletions wasm/wasm-node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ export async function bundleAsync(options) {

export { browserslistToTargets } from './browserslistToTargets.js'
export { Features } from './flags.js'
export { composeVisitors } from './composeVisitors.js';

0 comments on commit 4458481

Please sign in to comment.