-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't run a spec if the component uses @capacitor/core #1234
Comments
I have a similar problem. Importing
When debugging into the issue I discovered, that the capacitor.js doesn't actually export anything. Everything gets initialized but in the end it only gets assigned to the variable I'm using Capacitor 1.0.0-beta.25 and JEST 24.8.0 with following config: jest.config.js const esModules = ["@ionic", "@ionic-native", "@capacitor", "lodash-es"].join("|");
const tsconfig = require("./tsconfig.json")
const moduleNameMapper = require("tsconfig-paths-jest")(tsconfig);
module.exports = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|html)$': 'ts-jest',
'^.+\\.js$': 'babel-jest'
},
transformIgnorePatterns: [`node_modules/(?!${esModules})`],
resolver: '@nrwl/builders/plugins/jest/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
collectCoverage: true,
coverageReporters: ['html'],
moduleNameMapper,
}; babel.config.js module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
plugins: []
}; |
I found out two things:
|
I agree that this is a capacitor issue. BTW you can try adding a file export const Plugins = {}; to mock it out. Does that make it work for you? |
It does indeed! For those finding this issue from google: create the
|
Ok, good to know. I'll close this here and we can discuss how to smoothen out issues with Capacitor in tests in another issue over there... I think you were on the right track with the export not working for cjs. |
I post this here as well since Google pointed me to this issue before the capacitor one. I found a solution without needing a |
Stencil version:
I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request
Current behavior:
Expected behavior:
I want to be able to test an Ionic/Stencil app that uses Capacitor plugins.
Other information:
I followed the suggested links and found out that according to the Jest docs a setting should be set in order to transpile the package:
However that doesn't seem to do anything, same error.
One way to temporarily fix it was to open
node_modules/@capacitor/core/package.json
and change the"main"
field from"dist/esm/index.js"
to"dist/capacitor.js"
, which is a transpiled version. And I also had to add a null-check forPlugins
cause it couldn't read propertyStorage
ofundefined
. However that would break the build, so I have to manually do it only to run tests.Looking at the Rollup docs, it seems that the
"module"
field should be used for the ESM version, rather than the"main"
field:But not sure if that raises any other issues. Feel free to move this into the Capacitor repo, however seems like a bug that
transformIgnorePatterns
doesn't work.The text was updated successfully, but these errors were encountered: