Skip to content

Commit f9e1094

Browse files
committed
test: add test for TypeScript "compilation" with Babel
1 parent f22261f commit f9e1094

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

fixtures/js/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"compilerOptions": {}
3-
}
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true
4+
}
5+
}

test/functional.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,50 @@ module.exports = {
13201320
}).to.throw('wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)');
13211321
});
13221322

1323+
it('TypeScript can be compiled by Babel', (done) => {
1324+
const config = createWebpackConfig('www/build', 'dev');
1325+
config.setPublicPath('/build');
1326+
config.addEntry('main', ['./js/render.ts', './js/index.ts']);
1327+
config.configureBabel(function(config) {
1328+
config.presets = [
1329+
['@babel/preset-env', {
1330+
'targets': {
1331+
'chrome': 52,
1332+
},
1333+
}],
1334+
'@babel/typescript', // required preset
1335+
];
1336+
// not required, but recommended
1337+
config.plugins = ['@babel/proposal-class-properties'];
1338+
});
1339+
1340+
config.configureLoaderRule('javascript', loader => {
1341+
loader.test = /.(j|t)sx?$/; // let Babel to run over .tsx? files too
1342+
});
1343+
1344+
testSetup.runWebpack(config, (webpackAssert) => {
1345+
// check that babel-loader transformed the ts file
1346+
webpackAssert.assertOutputFileContains(
1347+
'main.js',
1348+
'document.getElementById(\'app\').innerHTML =',
1349+
);
1350+
1351+
testSetup.requestTestPage(
1352+
path.join(config.getContext(), 'www'),
1353+
[
1354+
'build/runtime.js',
1355+
'build/main.js',
1356+
],
1357+
(browser) => {
1358+
1359+
// assert that the ts module rendered
1360+
browser.assert.text('#app h1', 'Welcome to Your TypeScript App');
1361+
done();
1362+
},
1363+
);
1364+
});
1365+
});
1366+
13231367
it('When configured, Handlebars is compiled', (done) => {
13241368
const config = createWebpackConfig('www/build', 'dev');
13251369
config.setPublicPath('/build');

0 commit comments

Comments
 (0)