Skip to content
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

test: strongly typed tests #1404

Merged
merged 1 commit into from
Jan 23, 2025
Merged

test: strongly typed tests #1404

merged 1 commit into from
Jan 23, 2025

Conversation

43081j
Copy link
Collaborator

@43081j 43081j commented Jan 19, 2025

I'm leaving this as a draft for now just to show you what I was thinking @paulmillr

Basically, this moves the tests into src/ and converts them to typescript. I then ignored them from published files, etc.

All seems to work but these things had to change or need discussing (if we ever want this):

  • we need node16 resolution/module so *.mts is treated as ESM and import.meta exists
    • i manually diffed the build output before/after this change and it is identical
  • we have a test which tries to mock fs.Stat, but this isn't possible in ESM
    • i've commented on the relevant test

beforeEach(() => {
options.awaitWriteFinish = { pollInterval: 50, stabilityThreshold: 50 };
options.ignoreInitial = true;

// Stub fs.stat() to take a while to return.
sinon.stub(fs, 'stat').callsFake((path, cb) => {
_realStat(path, w(cb, 250));
statStub = sinon.stub(fs, 'stat').callsFake(async (path, cb) => {
Copy link
Collaborator Author

@43081j 43081j Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test can't have ever done what we thought since we moved to ESM here (i.e. since this became test.mjs)

in ESM you can't stub out a module's exports like this. which means it won't have been delaying the fs.stat calls

the test has been passing though... so maybe it just didn't actually test the thing it was trying to test? and passed because no such delay happened

for now, i skipped the test as it will throw if you try run it (sinon will throw because we try stub an ES module)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulmillr what do you think we should do about this test?

im not sure we can ever stub out fs like it used to in commonjs. so we'd have to test it another way, but not sure how as i don't understand the test case enough

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove it

@paulmillr
Copy link
Owner

Thanks @43081j -- looks great.

@43081j 43081j marked this pull request as ready for review January 21, 2025 09:39
@43081j
Copy link
Collaborator Author

43081j commented Jan 21, 2025

have published the PR now but we need to land #1403 first as this is branched off it

Moves the tests to typescript and cleans up some things which the
compiler picked up.
beforeEach(() => {
options.awaitWriteFinish = { pollInterval: 50, stabilityThreshold: 50 };
options.ignoreInitial = true;

// Stub fs.stat() to take a while to return.
sinon.stub(fs, 'stat').callsFake((path, cb) => {
_realStat(path, w(cb, 250));
statStub = sinon.stub(fs, 'stat').callsFake(async (path, cb) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove it

@paulmillr paulmillr merged commit 7b3e627 into main Jan 23, 2025
19 of 22 checks passed
@43081j 43081j deleted the typed-tests branch January 23, 2025 08:03
@43081j
Copy link
Collaborator Author

43081j commented Jan 23, 2025

I'll remove the disabled test in a follow-up if you don't beat me to it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants