Error: duplicate plugin/preset detected
obihill opened this issue · comments
Thanks for building this. I'm trying to use it to get code coverage via jest with puppeteer.
I'm having an issue when I run a test via jest CLI. Below is the full error log:
Running coverage on untested files...Failed to collect coverage from /Users/obihill/Documents/My_Projects/Restive/t
ech/libs/_test/src/files/sample.html.cov.js
ERROR: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
Duplicates detected are:
[
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "istanbul",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
},
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"options": {
"cwd": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"exclude": []
},
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
}
]
STACK: Error: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
Duplicates detected are:
[
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "istanbul",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
},
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"options": {
"cwd": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"exclude": []
},
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
}
]
at assertNoDuplicates (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:206:13)
at createDescriptors (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:114:3)
at createPluginDescriptors (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
at alias (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:63:53)
at cachedFunction (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/caching.js:62:27)
at cachedFunction.next (<anonymous>)
at evaluateSync (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/gensync/index.js:244:28)
at sync (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/gensync/index.js:84:14)
at plugins.plugins (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:28:77)
at mergeChainOpts (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-chain.js:319:26)
Test Suites: 1 failed, 1 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: 3.787s
Ran all test suites matching /html.cov.test.js/i.
Running coverage on untested files...Failed to collect coverage from /Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/src/files/sample.html.cov.js
ERROR: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
Duplicates detected are:
[
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "istanbul",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
},
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"options": {
"cwd": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"exclude": []
},
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
}
]
STACK: Error: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
Duplicates detected are:
[
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "istanbul",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
},
{
"alias": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"options": {
"cwd": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"exclude": []
},
"dirname": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test",
"ownPass": false,
"file": {
"request": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js",
"resolved": "/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/babel-plugin-istanbul/lib/index.js"
}
}
]
at assertNoDuplicates (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:206:13)
at createDescriptors (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:114:3)
at createPluginDescriptors (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
at alias (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:63:53)
at cachedFunction (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/caching.js:62:27)
at cachedFunction.next (<anonymous>)
at evaluateSync (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/gensync/index.js:244:28)
at sync (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/gensync/index.js:84:14)
at plugins.plugins (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-descriptors.js:28:77)
at mergeChainOpts (/Users/obihill/Documents/My_Projects/Restive/tech/libs/_test/node_modules/@babel/core/lib/config/config-chain.js:319:26)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
I'm not familiar with using Babel, but I followed your instructions for setting things up.
Here is my jest.config.json:
module.exports = {
verbose: true,
preset: 'jest-puppeteer',
testMatch: ["**/?(*.)+(spec|test).js"],
testTimeout: 15000,
collectCoverage: true,
collectCoverageFrom: ["src/(files|assets)/**/*.js"],
coverageReporters: ["text", "lcov", "json", "json-summary"],
setupFilesAfterEnv: ["jest-puppeteer-istanbul/lib/setup"],
reporters: ["default", "jest-puppeteer-istanbul/lib/reporter"],
coverageDirectory: "coverage"
}
Here is my .babelrc.js:
const plugins = []
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
plugins.push("istanbul")
}
module.exports = {
plugins: plugins
}
I followed your parcel example [with jest-puppeteer].
Thanks for your assistance.
Could you please try to remove the || process.env.NODE_ENV === "test"
part in your .babelrc.js
, and check if this issue still occur?
I removed it earlier when testing, but still get the same issue when running the following:
NODE_ENV=development jest
I only added it because jest uses test
.
It seems to be an issue with Babel, but I'm not familiar enough with it to know how to fix it. I don't use Babel so we can eliminate that I installed any duplicate plugins, but I don't know what jest, and add-ons, have done behind the scenes.
try TYPE=test jest
Generally speaking, you will run two jobs when doing E2E testing:
- A webserver who provides HTTP service.
- A Jest process who runs the test cases.
When using jest-puppeteer-istanbul
, you should only use babel-plugin-istanbul
when you running the first job.
In parcel-example-with-jest-puppeteer
, you can run yarn run dev
(or npx dev
) to do the job 1, and yarn run test
(or npx test
) for the job 2. By default, yarn run dev
will set NODE_ENV
as development
and yawrn run test
will set NODE_ENV
as test
. So in the babel configration file, babel-plugin-istanbul
will only be used when NODE_ENV
is development
I'm not really sure what TYPE=test
is supposed to change. I tried that and a few other things but I couldn't get it to work.
Everything is setup for Jest-puppeteer, and it works really well for tests via puppeteer, but I was looking for a way to do code coverage.
After some searching online I was able to find a workable solution using puppeteer-to-istanbul. This works directly with puppeteer so it was quite easy to setup. There is an extra step of using nyc to generate the coverage report, but I don't mind. I'll probably put it inside an npm script to make it a single command.
Thanks a lot for the effort and assistance with this. Your example helped me as I used your method with the click event handler to enable the functionality I needed.
Cheers.
Good to know you found a workable solution. Enjoy coding