gemini-testing / gemini-testing/testplane

testplane does not support ESM configuration files and .ts extension for test files

Open
#1,050 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
830
Forks
76
Avg merge
4d 10h
Merged PRs (30d)
14

Description

### Verify latest release

- [ ] I verified that the issue exists in the latest Hermione release

### Hermione version

8.23.1

### Last Hermione version that worked

_No response_

### Which area(s) of Hermione are affected? (leave empty if unsure)

_No response_

### Link to the code that reproduces this issue or a replay of the bug

_No response_

### Reproduction steps

1. Create a configuration file for Testplane with the html-reporter plugin. (`npm init testplane -- -v` with pnpm)
Configuration:
```
import type { ConfigInput } from 'testplane';

export default {
baseUrl: 'http://localhost',
browsers: {
chrome: {
automationProtocol: 'devtools',
desiredCapabilities: {
browserName: 'chrome'
},
headless: true
}
},
gridUrl: 'http://localhost:4444/wd/hub',
httpTimeout: 60000,
pageLoadTimeout: 0,
plugins: {
'@testplane/storybook': {
autoScreenshots: true,
// https://github.com/gemini-testing/hermione-storybook
// To run hermione storybook tests, use --storybook flag when launching hermione
// And dont forget to set 'buildStoriesJson: true' in storybook config if you use storybook@6
enabled: true,
localport: 6006,
storybookConfigDir: '.storybook'
},
'@testplane/test-filter': {
// https://github.com/gemini-testing/testplane-test-filter
enabled: true,
inputFile: 'testplane-filter.json'
// Create a file testplane-filter.json
// With the following structure:
// [
// {
// \"fullTitle\": \"some-title\",
// \"browserId\": \"some-browser\"
// }
// ]
},
'@testplane/url-decorator': {
// https://github.com/gemini-testing/testplane-url-decorator
enabled: true,
url: {
query: {
// Write your entries like \"text\": \"ololo\" to add query param &text=ololo
// You can also specify \"mode\": \"override\", if you need to overwrite existing param
}
}
},
'html-reporter/testplane': {
defaultView: 'all',
diffMode: '3-up-scaled',
// https://github.com/gemini-testing/html-reporter
enabled: true,
path: 'testplane-report'
}
},
resetCursor: false,
sets: {
desktop: {
browsers: ['chrome'],
files: ['**/tests/*.testplane.(t|j)s']
}
},
testTimeout: 90000
} satisfies ConfigInput;
```
2. Install the Testplane extension for VS Code.
4. Open the Testplane extension.

### Actual Behavior

When opening the extension, the following error message appears in the OUTPUT tab:
```
[WORKER 01:35:06] [01:35:06 +0300] Unable to read config from path e:\WEB_LEARN\SinsSoftware\Flippo\flippo-frontend\testplane.config.ts

[ERROR 01:35:06] Error: Testplane failed to start:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: e:\WEB_LEARN\SinsSoftware\Flippo\flippo-frontend\testplane.config.ts
require() of ES modules is not supported.
require() of e:\WEB_LEARN\SinsSoftware\Flippo\flippo-frontend\testplane.config.ts from E:\WEB_LEARN\SinsSoftware\Flippo\flippo-frontend\node_modules\.pnpm\testplane@8.23.1_@cspotcode+source-map-support@0.8.1_@types+node@22.10.5_ts-node@10.9.2_@type_2uf5nugpmtuodxde2bpdmktqoy\node_modules\testplane\build\src\config\index.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from e:\WEB_LEARN\SinsSoftware\Flippo\flippo-frontend\package.json.
```
Even when running via `npx testplane` instead of using the VS Code extension, the same error occurs.

After replacing the configuration file extension with .cts and using module.exports = {} syntax, the following issue occurs:

- The html-reporter plugin creates a folder with the necessary files (e.g., database and other artifacts).
- However, the .ts test files (e.g., example.testplane.ts) are not recognized, resulting in the following error:
```
[ERROR 03:35:26] TypeError: Unknown file extension ".ts" for E:\WEB_LEARN\SinsSoftware\Flippo\flippo-frontend\src\tests\example.testplane.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
at defaultLoad (node:internal/modules/esm/load:141:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
at async link (node:internal/modules/esm/module_job:76:21)
```

### Expected Behavior

The expected behavior aligns with the example provided in the Testplane blog:
testing-sidebar-f3c667ae110b1c90f9c5c7f2a5ab70d0

### Which Node.js version are you using?

20.10.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.