freezing-electrician-6256
11/01/2023, 5:20 PM"type": "module"
in my package.json i get errors running mocha unit tests. i get errors trying to import files in my tests.
i have set the ts-node/esm loader in in my .mocharc.json:
{
"extension": [
"ts"
],
"loader": "ts-node/esm",
"spec": "tests/**/*_test.ts",
"recursive": true
}
and i have "esm": true
in my tsconfig.json:
{
"compilerOptions": {
"module": "ES2020",
"target": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true
},
"ts-node": {
"compilerOptions": {
"module": "esnext"
},
"esm": true
}
}
(to be honest I probably don't need the ts-node block because i would expect es2020 and esnext to have the same effect for the purposes of this scenario, but I don't know much about es2020/esnext particulars).
i have been looking at issues such as https://github.com/TypeStrong/ts-node/issues/935. would appreciate if anyone has any pointers on this, thanks!Error: Cannot find module '/home/myuser/path/pulumi-component-resources/my_component' imported from /home/myuser/path/pulumi-component-resources/tests/my_component_test.ts
and i am doing the import like this
before(async function () {
// It's important to import the program _after_ the mocks are defined.
module = await import("../my_component");
});
the ts file does exist in the place expectedlittle-cartoon-10569
11/01/2023, 7:27 PMfreezing-electrician-6256
11/01/2023, 10:01 PMlittle-cartoon-10569
11/01/2023, 10:22 PMfreezing-electrician-6256
11/01/2023, 10:22 PMlittle-cartoon-10569
11/01/2023, 10:23 PM{
"name": "project",
"type": "module",
"module": "esnext",
"target": "es2020",
...
stale-answer-34162
11/02/2023, 7:41 PMlittle-cartoon-10569
11/02/2023, 7:41 PMstale-answer-34162
11/02/2023, 7:42 PMlittle-cartoon-10569
11/02/2023, 7:43 PMstale-answer-34162
11/02/2023, 7:43 PMlittle-cartoon-10569
11/02/2023, 7:44 PMstale-answer-34162
11/02/2023, 7:44 PMlittle-cartoon-10569
11/02/2023, 7:47 PMpromise()
method on OutputInstance<>
.
3. For AWS resources, set the ARN in your resource creation function in setMocks()
. You'll need to soooo often.
The recommendations are:
1. Write your tests before your code.
2. Don't write tests, describe decisions you've made about how you want your project to work.
3. Keep your tests short.