Skip to content

Commit c976242

Browse files
committed
Test ESM and CJS targets. [#12]
1 parent 94a2cfb commit c976242

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

tests/__snapshots__/index.test.ts.snap

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,104 @@ class ESTarget extends _react.default.Component<Props> {
22782278
exports.default = ESTarget;"
22792279
`;
22802280
2281+
exports[`babel-plugin-typescript-to-proptypes works correctly when transpiling to CJS modules 1`] = `
2282+
"\\"use strict\\";
2283+
2284+
Object.defineProperty(exports, \\"__esModule\\", {
2285+
value: true
2286+
});
2287+
exports.default = void 0;
2288+
2289+
var _propTypes = _interopRequireDefault(require('prop-types'));
2290+
2291+
var _react = _interopRequireDefault(require('react'));
2292+
2293+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2294+
2295+
interface Props {
2296+
name: string;
2297+
}
2298+
2299+
class ESTarget extends _react.default.Component<Props> {
2300+
static propTypes = {
2301+
name: _propTypes.default.string.isRequired
2302+
};
2303+
2304+
render() {
2305+
return null;
2306+
}
2307+
2308+
}
2309+
2310+
exports.default = ESTarget;"
2311+
`;
2312+
2313+
exports[`babel-plugin-typescript-to-proptypes works correctly when transpiling to CJS modules 2`] = `
2314+
"\\"use strict\\";
2315+
2316+
exports.__esModule = true;
2317+
exports.default = void 0;
2318+
2319+
var _propTypes = _interopRequireDefault(require('prop-types'));
2320+
2321+
var _react = _interopRequireDefault(require('react'));
2322+
2323+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2324+
2325+
interface Props {
2326+
name: string;
2327+
}
2328+
2329+
class ESTarget extends _react.default.Component<Props> {
2330+
static propTypes = {
2331+
name: _propTypes.default.string.isRequired
2332+
};
2333+
2334+
render() {
2335+
return null;
2336+
}
2337+
2338+
}
2339+
2340+
exports.default = ESTarget;"
2341+
`;
2342+
2343+
exports[`babel-plugin-typescript-to-proptypes works correctly when transpiling to ESM modules 1`] = `
2344+
"import _pt from 'prop-types';
2345+
import React from 'react';
2346+
interface Props {
2347+
name: string;
2348+
}
2349+
export default class ESTarget extends React.Component<Props> {
2350+
static propTypes = {
2351+
name: _pt.string.isRequired
2352+
};
2353+
2354+
render() {
2355+
return null;
2356+
}
2357+
2358+
}"
2359+
`;
2360+
2361+
exports[`babel-plugin-typescript-to-proptypes works correctly when transpiling to ESM modules 2`] = `
2362+
"import _pt from 'prop-types';
2363+
import React from 'react';
2364+
interface Props {
2365+
name: string;
2366+
}
2367+
export default class ESTarget extends React.Component<Props> {
2368+
static propTypes = {
2369+
name: _pt.string.isRequired
2370+
};
2371+
2372+
render() {
2373+
return null;
2374+
}
2375+
2376+
}"
2377+
`;
2378+
22812379
exports[`babel-plugin-typescript-to-proptypes works correctly when using ALL the things 1`] = `
22822380
"\\"use strict\\";
22832381

tests/index.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ describe('babel-plugin-typescript-to-proptypes', () => {
9393
).toMatchSnapshot();
9494
});
9595

96+
it('works correctly when transpiling to ESM modules', () => {
97+
expect(
98+
transform(path.join(__dirname, './fixtures/special/es-target.ts'), {
99+
presets: [['@babel/preset-env', { targets: { node: 'current' }, modules: false }]],
100+
}),
101+
).toMatchSnapshot();
102+
103+
// loose
104+
expect(
105+
transform(path.join(__dirname, './fixtures/special/es-target.ts'), {
106+
presets: [
107+
['@babel/preset-env', { targets: { node: 'current' }, modules: false, loose: true }],
108+
],
109+
}),
110+
).toMatchSnapshot();
111+
});
112+
113+
it('works correctly when transpiling to CJS modules', () => {
114+
expect(
115+
transform(path.join(__dirname, './fixtures/special/es-target.ts'), {
116+
presets: [['@babel/preset-env', { targets: { node: 'current' }, modules: 'commonjs' }]],
117+
}),
118+
).toMatchSnapshot();
119+
120+
// loose
121+
expect(
122+
transform(path.join(__dirname, './fixtures/special/es-target.ts'), {
123+
presets: [
124+
['@babel/preset-env', { targets: { node: 'current' }, modules: 'commonjs', loose: true }],
125+
],
126+
}),
127+
).toMatchSnapshot();
128+
});
129+
96130
it('works correctly when using the typescript preset', () => {
97131
expect(
98132
transform(path.join(__dirname, './fixtures/special/ts-preset.ts'), {

0 commit comments

Comments
 (0)