Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test: stop relying on pnpm's NODE_PATH in build and core tests (#6372)

sangwookb0d1e922e7f7
diff --git a/packages/build/package.json b/packages/build/package.json
index aae7d38d02..95fe6722e7 100644
--- a/packages/build/package.json
+++ b/packages/build/package.json
@@ -54,6 +54,7 @@
"lightningcss": "^1.32.0"
},
"devDependencies": {
+ "enhanced-resolve": "^5.21.6",
"esbuild": "catalog:"
},
"peerDependenciesMeta": {
diff --git a/packages/build/src/vite.build.test.ts b/packages/build/src/vite.build.test.ts
index fa55a8bc3b..8c82ab4394 100644
--- a/packages/build/src/vite.build.test.ts
+++ b/packages/build/src/vite.build.test.ts
@@ -205,7 +205,9 @@ function itSplitsCorrectly(get: () => Built) {
// output means running the same pass, or the build quietly loses the prefixes
// the original had.
it('keeps the vendor prefixing StyleX applies', () => {
- expect(get().css).toContain('-webkit-');
+ // `-webkit-box-orient` is authored in source, so only a prefix the pass
+ // adds shows that it ran.
+ expect(get().css).toContain('-webkit-user-select');
});
it('links the stylesheet from the page', () => {
diff --git a/packages/core/src/ButtonGroup/ButtonGroup.test.tsx b/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
index 87d8910e72..ec2eb8f106 100644
--- a/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
+++ b/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
@@ -18,6 +18,7 @@ import userEvent from '@testing-library/user-event';
import {transformSync} from '@babel/core';
import stylexBabelPlugin from '@stylexjs/babel-plugin';
import {readFileSync} from 'node:fs';
+import {createRequire} from 'node:module';
import path from 'node:path';
import {ButtonGroup} from './ButtonGroup';
import {Button} from '../Button';
@@ -250,14 +251,20 @@ describe('ButtonGroup', () => {
function compileButtonRules(): CompiledRule[] {
const repoRoot = path.resolve(__dirname, '../../../..');
const buttonSrc = path.resolve(__dirname, '../Button/Button.tsx');
+ // Babel looks bare preset names up from the cwd, the repo root, which
+ // does not declare them. Resolve them from this package, which does.
+ const require = createRequire(__filename);
const result = transformSync(readFileSync(buttonSrc, 'utf8'), {
babelrc: false,
configFile: false,
filename: buttonSrc,
presets: [
- ['@babel/preset-typescript', {isTSX: true, allExtensions: true}],
- ['@babel/preset-react', {runtime: 'automatic'}],
+ [
+ require.resolve('@babel/preset-typescript'),
+ {isTSX: true, allExtensions: true},
+ ],
+ [require.resolve('@babel/preset-react'), {runtime: 'automatic'}],
],
plugins: [
[
diff --git a/packages/core/src/Selector/Selector.source-build.test.mjs b/packages/core/src/Selector/Selector.source-build.test.mjs
index 342cb87f8b..67ec6cff71 100644
--- a/packages/core/src/Selector/Selector.source-build.test.mjs
+++ b/packages/core/src/Selector/Selector.source-build.test.mjs
@@ -2,12 +2,13 @@
/**
* @file Selector.source-build.test.mjs
- * @input Uses Babel, next/babel, the StyleX compiler, and Selector source
+ * @input Uses Babel, an arrow-lowering plugin, the StyleX compiler, and Selector source
* @output Verifies raw Selector source survives a consumer's Babel pipeline
* @position Regression test for Selector source-build compatibility
*/
import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {transformAsync} from '@babel/core';
@@ -17,6 +18,19 @@ import {describe, expect, it} from 'vitest';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, '../../../..');
const SELECTOR_SOURCE = path.join(__dirname, 'Selector.tsx');
+// Babel looks bare preset names up from the cwd, the repo root, which does
+// not declare them. Resolve them from this package, which does.
+const require = createRequire(import.meta.url);
+
+// What broke #5464: a consumer preset (there, next/babel) lowering arrows to
+// function expressions, which StyleX cannot evaluate. This does only that.
+const lowerArrows = () => ({
+ visitor: {
+ ArrowFunctionExpression(arrow) {
+ arrow.arrowFunctionToExpression();
+ },
+ },
+});
const EXPECTED_PADDING_DECLARATIONS = [
'padding-block:calc((var(--size-element-sm) - max(min(var(--spacing-5),max(var(--size-element-sm) - 2 * var(--border-width),1.5em)),20px,1rem) - 2 * var(--border-width)) / 2)',
@@ -25,20 +39,19 @@ const EXPECTED_PADDING_DECLARATIONS = [
];
describe('Selector source-build compatibility (#5464)', () => {
- it('compiles after next/babel lowers module-scope arrows', async () => {
+ it('compiles after a consumer preset lowers module-scope arrows', async () => {
const source = await fs.readFile(SELECTOR_SOURCE, 'utf8');
const result = await transformAsync(source, {
babelrc: false,
- caller: {
- name: 'selector-source-build-test',
- isDev: false,
- isServer: false,
- supportsStaticESM: false,
- },
configFile: false,
- envName: 'production',
filename: SELECTOR_SOURCE,
- presets: ['next/babel'],
+ presets: [
+ [
+ require.resolve('@babel/preset-typescript'),
+ {isTSX: true, allExtensions: true},
+ ],
+ [require.resolve('@babel/preset-react'), {runtime: 'automatic'}],
+ ],
plugins: [
[
stylexBabelPlugin,
@@ -53,6 +66,7 @@ describe('Selector source-build compatibility (#5464)', () => {
},
},
],
+ lowerArrows,
],
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 35d26bde44..b8136b680e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -702,6 +702,9 @@ importers:
specifier: 'catalog:'
devDependencies:
+ enhanced-resolve:
+ specifier: ^5.21.6
+ version: 5.21.6
esbuild:
specifier: '>=0.28.1'
version: 0.28.1