-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Expose snapshot directory through test.meta #2444
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Let's make snapshotDirectory
a getter. We don't need to resolve it in test files that don't use snapshots.
Regarding the CI failures, I think you need to add mem
to this list, since it messes with some expected stack traces:
Line 10 in 447d371
const avaDependencies = /\/node_modules\/(?:@ava\/babel|@ava\/require-precompiled|append-transform|empower-core|nyc|require-precompiled|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//; |
(We're trying to clean this up: #2420)
There's some other failures due to perhaps some tests that are a little too low level, and are now breaking. I haven't looked into it much yet.
Ah, that's what you meant with
Thanks, wasn't aware. You might be right about that. I'll try it out. I was being lazy/too tired to run the whole test suite on my machine. Shouldn't have created the final PR (draft could have worked). Sorry about that.
Yeah, I think I might be using |
Co-Authored-By: Mark Wubben <[email protected]>
Also, is there no feasible way to only run one test with |
|
Try |
Will do, thanks! So your theory is that |
oO, looks promising. I’ll give it a go. Thanks! |
Follow-up: |
No go ;( Fumbling in the dark... So I have a test fixture which uses AVA syntax. The |
Looks like I don't have to mess with |
const dir = determineSnapshotDir({file, fixedLocation, projectDir}); | ||
const relFile = path.relative(projectDir, resolveSourceFile(file)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: In order to not have to export both determineSnapshotDir()
and resolveSourceFile()
I changed the signature of determineSnapshotDir()
to take the "raw" file instead of the source file (it resolves the source file on its own).
Caveat: resolveSourceFile()
is called twice for load()
(once more to determine the relative path). But since it's memoized, I think it should be fine, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine.
lib/runner.js
Outdated
@@ -54,7 +54,11 @@ class Runner extends Emittery { | |||
let hasStarted = false; | |||
let scheduledStart = false; | |||
const meta = Object.freeze({ | |||
file: options.file | |||
file: this.file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't really matter, I guess, but should I revert this to use options
again? I switched to this
since I think that's what's being used elsewhere, but now it looks kinda inconsistent when snapshotDirectory()
is using options
. Opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I'll change it back.
test('meta is test.meta', t => { | ||
t.is(meta, test.meta); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this test necessary? I added it to not have to add two tests for every property as was done for file
(checking both meta.property
and test.meta.property
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it won't hurt 😄
I'm looking to remove this extra export in #2435.
test-tap/fixture/meta.js
Outdated
test('test.meta.file', t => { | ||
t.is(test.meta.file, __filename); | ||
test('meta.snapshotDirectory', t => { | ||
t.regex(meta.snapshotDirectory, /.*snapshot-fixture.*/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regex specific enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea it's fine. Though you don't need the .*
.
docs/01-writing-tests.md
Outdated
|
||
Helper files can determine the filename of the test being run by reading `test.meta.file`. This eliminates the need to pass `__filename` from the test to helpers. | ||
Access metadata of the test being run by reading `test.meta`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to keep this short. Found the previous text a little redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea… helper files are less emphasized within AVA core anyhow.
@novemberborn Okidoki, I think we're good to go here. Added some self-review comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I've pushed some tweaks, let's see if I didn't break CI.
Anything else from your end?
docs/01-writing-tests.md
Outdated
|
||
Helper files can determine the filename of the test being run by reading `test.meta.file`. This eliminates the need to pass `__filename` from the test to helpers. | ||
Access metadata of the test being run by reading `test.meta`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea… helper files are less emphasized within AVA core anyhow.
lib/runner.js
Outdated
@@ -54,7 +54,11 @@ class Runner extends Emittery { | |||
let hasStarted = false; | |||
let scheduledStart = false; | |||
const meta = Object.freeze({ | |||
file: options.file | |||
file: this.file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I'll change it back.
const dir = determineSnapshotDir({file, fixedLocation, projectDir}); | ||
const relFile = path.relative(projectDir, resolveSourceFile(file)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine.
test('meta is test.meta', t => { | ||
t.is(meta, test.meta); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it won't hurt 😄
I'm looking to remove this extra export in #2435.
test-tap/fixture/meta.js
Outdated
test('test.meta.file', t => { | ||
t.is(test.meta.file, __filename); | ||
test('meta.snapshotDirectory', t => { | ||
t.regex(meta.snapshotDirectory, /.*snapshot-fixture.*/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea it's fine. Though you don't need the .*
.
LGTM! |
meta.snapshotDirectory
Closes #1984
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
IssueHunt has been backed by the following sponsors. Become a sponsor