Skip to content

Commit

Permalink
Add babel plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgomes committed Sep 18, 2024
1 parent d9ea190 commit 061b7eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/babel-preset-default/test/fixtures/polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Note: this fixture may need to be updated when the browserslist or the
// core-js dependencies are updated.
// It should always test a feature that is supported, but requires
// a polyfill to work across all supported browsers.
const foo = new URLSearchParams();
window.fooSize = foo.size;
18 changes: 18 additions & 0 deletions packages/babel-preset-default/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ describe( 'Babel preset default', () => {

expect( output.code ).toMatchSnapshot();
} );

test( 'transpilation includes magic comment when using the addPolyfillComments option', () => {
const filename = path.join( __dirname, '/fixtures/polyfill.js' );
const input = readFileSync( filename );

const output = transform( input, {
filename,
configFile: false,
envName: 'production',
presets: [ babelPresetDefault ],
caller: {
name: 'WP_BUILD_MAIN',
addPolyfillComments: true,
},
} );

expect( output.code ).toContain( '/* wp:polyfill */' );
} );
} );

0 comments on commit 061b7eb

Please sign in to comment.