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

Expose snapshot directory through test.meta #2444

Merged
merged 14 commits into from
Apr 10, 2020

Conversation

ulken
Copy link
Contributor

@ulken ulken commented Apr 7, 2020

Closes #1984


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


IssueHunt has been backed by the following sponsors. Become a sponsor

@ulken ulken mentioned this pull request Apr 7, 2020
Copy link
Member

@novemberborn novemberborn left a 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:

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.

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

Let's make snapshotDirectory a getter. We don't need to resolve it in test files that don't use snapshots.

Ah, that's what you meant with getter – smart! I was looking for a way to only compute the path if snapshots was actually used. First turned to options.snapshotDir, but then learned that was just used as a "prefix". A lazy getter would solve it just perfectly.

Regarding the CI failures, I think you need to add mem to this list, since it messes with some expected stack traces:

const avaDependencies = /\/node_modules\/(?:@ava\/babel|@ava\/require-precompiled|append-transform|empower-core|nyc|require-precompiled|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;

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.

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.

Yeah, I think I might be using mem wrongly. I'm having a hard time debugging tap tests, though. console.log won't output anything (swallowed?). Can you run tap in debug mode with breakpoints in VS Code, do you know?

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

Also, is there no feasible way to only run one test with tap? Like AVA's t.only()? I looked at the docs, but it was so tedious...

@novemberborn
Copy link
Member

Also, is there no feasible way to only run one test with tap? Like AVA's t.only()? I looked at the docs, but it was so tedious...

npx tap test.js --grep=title or something like that. Or you can add {only: true} as the final argument, I think.

@novemberborn
Copy link
Member

I'm having a hard time debugging tap tests, though. console.log won't output anything (swallowed?). Can you run tap in debug mode with breakpoints in VS Code, do you know?

Try console.error(). I've never actually tried to debug tap tests.

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

Try console.error(). I've never actually tried to debug tap tests.

Will do, thanks! So your theory is that console.error() is not swallowed?

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

npx tap test.js --grep=title or something like that. Or you can add {only: true} as the final argument, I think.

oO, looks promising. I’ll give it a go. Thanks!

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

npx tap test.js --grep=title or something like that. Or you can add {only: true} as the final argument, I think.

Follow-up: --grep worked fine. The optional option object ({only: true}) is passed as the second parameter, not the third/last (the callback comes last). Also, tap --only is required to only run "only" tests. Good to know, thanks!

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

Try console.error(). I've never actually tried to debug tap tests.

No go ;( Fumbling in the dark...

So I have a test fixture which uses AVA syntax. The tap test for api.js runs that file. Any logs, throws etc. inside the fixture file don't show up in the terminal. Any ideas?

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

Looks like I don't have to mess with beautify-stack/avaDependencies after all. At least all tests pass locally. Still have to await CI...

Comment on lines +432 to +433
const dir = determineSnapshotDir({file, fixedLocation, projectDir});
const relFile = path.relative(projectDir, resolveSourceFile(file));
Copy link
Contributor Author

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?

Copy link
Member

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,
Copy link
Contributor Author

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?

Copy link
Member

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.

Comment on lines +3 to +5
test('meta is test.meta', t => {
t.is(meta, test.meta);
});
Copy link
Contributor Author

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).

Copy link
Member

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('test.meta.file', t => {
t.is(test.meta.file, __filename);
test('meta.snapshotDirectory', t => {
t.regex(meta.snapshotDirectory, /.*snapshot-fixture.*/);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regex specific enough?

Copy link
Member

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 .*.


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`.
Copy link
Contributor Author

@ulken ulken Apr 8, 2020

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.

Copy link
Member

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.

@ulken
Copy link
Contributor Author

ulken commented Apr 8, 2020

@novemberborn Okidoki, I think we're good to go here. Added some self-review comments.

Copy link
Member

@novemberborn novemberborn left a 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?


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`.
Copy link
Member

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,
Copy link
Member

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.

Comment on lines +432 to +433
const dir = determineSnapshotDir({file, fixedLocation, projectDir});
const relFile = path.relative(projectDir, resolveSourceFile(file));
Copy link
Member

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.

Comment on lines +3 to +5
test('meta is test.meta', t => {
t.is(meta, test.meta);
});
Copy link
Member

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('test.meta.file', t => {
t.is(test.meta.file, __filename);
test('meta.snapshotDirectory', t => {
t.regex(meta.snapshotDirectory, /.*snapshot-fixture.*/);
Copy link
Member

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 .*.

@ulken
Copy link
Contributor Author

ulken commented Apr 10, 2020

LGTM!

@novemberborn novemberborn changed the title Expose meta.snapshotDirectory Expose snapshot directory through test.meta Apr 10, 2020
@novemberborn novemberborn merged commit cb5f9f7 into avajs:master Apr 10, 2020
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.

Expose config object
2 participants