I need some help with TS + Mocha, not specifically...
# typescript
I need some help with TS + Mocha, not specifically to do with Pulumi. I'm testing some Pulumi resource components, but I'm finding that my updated TS code (which is compiling correctly to the expected ./lib directory) isn't always being found. My beginner npm/node knowledge is hampering my investigation.
When I run my tests, the .ts code is correctly compiling. In the correct directory under ./lib, I can see the updated .d.ts files, .js iles, etc.
However when I then run Mocha, it's not finding new files. They're there, it's just reporting that it can't find them. I don't know if it's looking in the wrong place, or it's refusing to update some internal cache, or what.
What can I pare back to work towards finding the source of the problem? Should I try creating a .js file in my ./lib file and seeing if Mocha can find that?
I have
"lib": "./lib", "test": "."
in my package.json, but I don't know what they're for or if they're right.
I haven't defined any "dependencies": everything is defined in "devDependencies".
The error message always looks like this: TypeError: Unable to require file: lib/test/mocha/pulumi/FileThatExists.spec.d.ts
I had some tweaks to defaults (e.g. location of .mocharc.json file) that I removed; I think everything is now in npm's and Mocha's opinionate preference locations. No more complaining about not finding files that exist.
Unfortunately, I'm now getting compile errors, but only if I specify a single spec file (
npm run test --spec **/Si*.spec.ts
). If I use a slightly broader ant-expression that finds more than one file (
npm run test --spec **/S*.spec.ts
) then everything is fine, even the tests in the file that previously didn't compile
All the compile failures strictly sensible: I'm using code like
and it's complaining with this:
error TS2339: Property 'rule' does not exist on type 'Output<BucketServerSideEncryptionConfiguration | undefined>'.
Property 'rule' does not exist on type 'OutputInstance<BucketServerSideEncryptionConfiguration | undefined>'.
No idea why the complaints go away when I run the tests in more than one file, though.
Or how to fix the issue: the serverSideEncryptionConfiguration does exist, but I suppose the type can't be lifted out of
Output<BucketServerSideEncryptionConfiguration | undefined>
so TypeScript / tslint has a rant.
If anyone comes across this thread and has a suggestion, I'd love to hear it. For now, I'm going to lower the strictness of my linting when running tests. Which isn't ideal..