wonderful-jewelry-41731
08/24/2022, 11:46 AMwith-jest
as a starter to try jest, it works fine until I import a class where i'm importing @plasmo/storage
here is the error:
src/tests/bg/tabs.test.ts
● Test suite failed to run
Cannot find module '@plasmohq/storage' from 'src/bg/local-storage.ts'
Require stack:
src/bg/local-storage.ts
src/bg/tabs.ts
src/tests/bg/tabs.test.ts
> 1 | import { Storage } from "@plasmohq/storage"
| ^
2 |
3 | /*
4 | Cache: chrome.storage.local
at Resolver._throwModNotFoundError (node_modules/.pnpm/jest-resolve@28.1.3/node_modules/jest-resolve/build/resolver.js:491:11)
at Object.<anonymous> (src/bg/local-storage.ts:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 8.707 s
Ran all test suites.
ELIFECYCLE Test failed. See above for more details.
I think jest is trying to import the package from src
as in the config file we have :
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: "<rootDir>/"
}),
How can I fix this ?sticky-dress-98131
08/24/2022, 11:46 AMwonderful-jewelry-41731
08/24/2022, 11:49 AMimport { LocalStorage } from "./local-storage"
export class Tabs {
public static createTab(
url: string,
callback?: (tab: chrome.tabs.Tab) => void
) {
chrome.tabs.create({ url: url }, (createdTab: chrome.tabs.Tab) => {
callback(createdTab)
})
}
}
Adding import to plasmo storage package or importing a class that uses the package will throw error
import { Storage } from "@plasmohq/storage"