jestjs - Typescript `declare global` preventing Jest test suites from running -


my app using react, redux, , jest has typescript file code in it:

declare global {   interface window { eventsource: any;}    class eventsource {     errorers: any;     onerror: any;     onmessage: () => void;      addeventlistener(event: string, cb: () => void): void;      constructor(name: string);   } } 

i'm using jest test framework run tests on other areas in app use es6 javascript , work fine. unfortunately, there 2 test suites prevented running because of because of following error , it:

/users/blyncsy/documents/blyncsyu/client/app/bundles/analytic/data-hub.ts:3 declare global {         ^^^^^^ syntaxerror: unexpected identifier    @ transformandbuildscript (node_modules/jest-runtime/build/transform.js:321:12)   @ object.<anonymous> (app/bundles/pulse/actions/odanalyzeractions.js:2:16)   @ object.<anonymous> (app/bundles/pulse/containers/od-analyzer/odlinerenderer.js:6:26) 

other pieces of same typescript file screw test runner if 1 listed above commented out. file referenced in actions file being tested in first test suite, , action file being reference in file being tested second suite. i'm assuming needs done pre-compile .ts file before encountered tests, have not been able figure out how it. here webpack config:

/* eslint comma-dangle: ["error",  {"functions": "never", "arrays": "only-multiline", "objects":  "only-multiline"} ] */  const webpack = require('webpack'); const pathlib = require('path');  const devbuild = process.env.node_env !== 'production';  const config = {   entry: [     'es5-shim/es5-shim',     'es5-shim/es5-sham',     'babel-polyfill',     './app/bundles/analytic',     './app/bundles/pulse/startup/registration',   ],   output: {     filename: 'webpack-bundle.js',     path: pathlib.resolve(__dirname, '../app/assets/webpack'),   },   devtool: "source-map",   resolve: {     extensions: [".ts", ".tsx", '.js', '.jsx'],   },   plugins: [     new webpack.environmentplugin({ node_env: 'development' }),   ],   module: {     rules: [       {         test: /travel-info-type.ts/,         use: [{           loader: 'expose-loader',           options: 'travelinfotype'         }]       },       {         test: /heatmap-getter.ts/,         use: [{           loader: 'expose-loader',           options: 'heatmapgetter'         }]       },       {         test: /data-hub.ts/,         use: [{           loader: 'expose-loader',           options: 'datahub'         }]       },       {         test: require.resolve('react'),         use: {           loader: 'imports-loader',           options: {             shim: 'es5-shim/es5-shim',             sham: 'es5-shim/es5-sham',           }         },       },       {         test: /\.jsx?$/,         use: 'babel-loader',         exclude: /node_modules/,       },       // files '.ts' or '.tsx' extension handled 'awesome-typescript-loader'.       { test: /\.tsx?$/, loader: "awesome-typescript-loader" },        // output '.js' files have sourcemaps re-processed 'source-map-loader'.       { enforce: "pre", test: /\.js$/, loader: "source-map-loader" },       // extract css files       {         test: /\.css$/,         use: ['style-loader', 'css-loader'],       },     ],   }, };  module.exports = config;  if (devbuild) {   console.log('webpack dev build rails'); // eslint-disable-line no-console   module.exports.devtool = 'eval-source-map'; } else {   console.log('webpack production build rails'); // eslint-disable-line no-console } 

any appreciated!

your error

/users/blyncsy/documents/blyncsyu/client/app/bundles/analytic/data-hub.ts:3

indicates jest trying run .ts file. need use ts-jest transform ts file.

more

this documented in typescript docs : https://facebook.github.io/jest/docs/getting-started.html#using-typescript


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -