From 46170509b4d242028197c857e903aaa55ce50bfb Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Mon, 5 Apr 2021 17:39:26 +0530 Subject: [PATCH] test: ts esnext (#2584) --- .../config-format/typescript-esnext/main.ts | 1 + .../typescript-esnext/package.json | 3 ++ .../typescript-esnext/tsconfig.json | 6 ++++ .../typescript-esnext/typescript.test.js | 30 +++++++++++++++++++ .../typescript-esnext/webpack.config.ts | 13 ++++++++ 5 files changed, 53 insertions(+) create mode 100644 test/build/config-format/typescript-esnext/main.ts create mode 100644 test/build/config-format/typescript-esnext/package.json create mode 100644 test/build/config-format/typescript-esnext/tsconfig.json create mode 100644 test/build/config-format/typescript-esnext/typescript.test.js create mode 100644 test/build/config-format/typescript-esnext/webpack.config.ts diff --git a/test/build/config-format/typescript-esnext/main.ts b/test/build/config-format/typescript-esnext/main.ts new file mode 100644 index 00000000000..6b4ec5de3a4 --- /dev/null +++ b/test/build/config-format/typescript-esnext/main.ts @@ -0,0 +1 @@ +console.log('Rimuru Tempest'); diff --git a/test/build/config-format/typescript-esnext/package.json b/test/build/config-format/typescript-esnext/package.json new file mode 100644 index 00000000000..3dbc1ca591c --- /dev/null +++ b/test/build/config-format/typescript-esnext/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/test/build/config-format/typescript-esnext/tsconfig.json b/test/build/config-format/typescript-esnext/tsconfig.json new file mode 100644 index 00000000000..e0ba2dc7a46 --- /dev/null +++ b/test/build/config-format/typescript-esnext/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "module": "esnext", + "allowSyntheticDefaultImports": true + } +} diff --git a/test/build/config-format/typescript-esnext/typescript.test.js b/test/build/config-format/typescript-esnext/typescript.test.js new file mode 100644 index 00000000000..683640ffd58 --- /dev/null +++ b/test/build/config-format/typescript-esnext/typescript.test.js @@ -0,0 +1,30 @@ +// eslint-disable-next-line node/no-unpublished-require +const { run, isWebpack5 } = require('../../../utils/test-utils'); +const { existsSync } = require('fs'); +const { resolve } = require('path'); + +describe('webpack cli', () => { + it('should support typescript esnext file', async () => { + const isMacOS = process.platform === 'darwin'; + const majorNodeVersion = process.version.slice(1, 3); + if (majorNodeVersion < 14) { + expect(true).toBe(true); + + return; + } + + if (isMacOS && !isWebpack5) { + expect(true).toBe(true); + + return; + } + + const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.ts'], { + nodeOptions: ['--loader=ts-node/esm'], + }); + expect(stderr).not.toBeFalsy(); + expect(stdout).toBeTruthy(); + expect(exitCode).toBe(0); + expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy(); + }); +}); diff --git a/test/build/config-format/typescript-esnext/webpack.config.ts b/test/build/config-format/typescript-esnext/webpack.config.ts new file mode 100644 index 00000000000..f382c1724f1 --- /dev/null +++ b/test/build/config-format/typescript-esnext/webpack.config.ts @@ -0,0 +1,13 @@ +/* eslint-disable node/no-unsupported-features/es-syntax */ +import * as path from 'path'; + +const config = { + mode: 'production', + entry: './main.ts', + output: { + path: path.resolve('dist'), + filename: 'foo.bundle.js', + }, +}; + +export default config;