Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumontjonathan committed Jan 5, 2025
1 parent 5096fdb commit 4a7ce53
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
'use strict';

jest.autoMockOff();
jest.mock('@dual-bundle/import-meta-resolve');

/* eslint-disable quotes */
const { transformSync } = require('@babel/core');
const stylexPlugin = require('../../src/index');
const jsx = require('@babel/plugin-syntax-jsx');
const { utils } = require('@stylexjs/shared');
const { moduleResolve } = require('@dual-bundle/import-meta-resolve');

const hash = utils.hash;

Expand Down Expand Up @@ -402,4 +404,38 @@ describe('Evaluation of imported values works based on configuration', () => {
`);
});
});

describe('Module resolution commonJS', () => {
test('Recognizes .ts stylex imports when resolving .js relative imports', () => {
moduleResolve.mockReturnValue({
pathname: '/project/otherFile.stylex.ts',
});

const transformation = transform(
`
import stylex from 'stylex';
import { MyTheme } from './otherFile.stylex.js';
const styles = stylex.create({
red: {
color: MyTheme.__themeName__,
}
});
stylex(styles.red);
`,
{
unstable_moduleResolution: { type: 'commonJS' },
},
);

expect(transformation.code).toMatchInlineSnapshot(`
"import _inject from "@stylexjs/stylex/lib/stylex-inject";
var _inject2 = _inject;
import stylex from 'stylex';
import './otherFile.stylex.js';
import { MyTheme } from './otherFile.stylex.js';
_inject2(".xoh8dld{color:xb897f7}", 3000);
"xoh8dld";"
`);
});
});
});

0 comments on commit 4a7ce53

Please sign in to comment.