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

Snapshot location #1489

Merged
merged 16 commits into from
Sep 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#1459 Resolve custom location for non sourcemap tests.
 - throw on invalid sourcemap
 - remove extra snapshot-location cli option
  • Loading branch information
impaler committed Aug 7, 2017
commit 2c344fabf14c5dea0642d053b20020f67b276c14
5 changes: 1 addition & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ exports.run = () => {
--timeout, -T Set global timeout
--concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)
--update-snapshots, -u Update snapshots
--snapshot-location, -l Manual location for snapshot fixtures

Examples
ava
Expand Down Expand Up @@ -98,8 +97,7 @@ exports.run = () => {
w: 'watch',
T: 'timeout',
c: 'concurrency',
u: 'update-snapshots',
l: 'snapshot-location'
u: 'update-snapshots'
}
});

Expand Down Expand Up @@ -147,7 +145,6 @@ exports.run = () => {
timeout: conf.timeout,
concurrency: conf.concurrency ? parseInt(conf.concurrency, 10) : 0,
updateSnapshots: conf.updateSnapshots,
snapshotLocation: conf.snapshotLocation,
color: conf.color
});

Expand Down
10 changes: 7 additions & 3 deletions lib/snapshot-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function tryReadSourceMap(file) {
try {
return JSON.parse(content.toString());
} catch (err) {
console.error('Parse error on sourcemap', file);
return null;
console.error('Parse error on snapshot sourcemap', file);
throw err;
}
}
}
Expand Down Expand Up @@ -371,7 +371,11 @@ function determineSnapshotDir(options) {
const projectDir = options.projectDir;
const testDir = determineSourceMappedDir(options);
if (options.location) {
return testDir; // No need for a preset foldername in custom locations
// "snapshotLocation" in ava package.json config, snapshots derive a location
// relative from the source testDir not the preset "__snapshots__" folder names
Copy link
Member

Choose a reason for hiding this comment

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

When options.location becomes options.fixedLocation this comment becomes unnecessary since it's clear what is expected of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I guess the comment highlighted some of the ambiguitiy, please checkout the latest revision.

const resolvedLocation = path.resolve(options.projectDir, options.location);
const relativeTestLocation = options.testDir.replace(options.projectDir, '');
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this refer to testDir, rather than options.testDir?

Also, you should be able to use path.relative(projectDir, testDir) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, please checkout the latest revision.

return path.join(resolvedLocation, relativeTestLocation);
}
const parts = new Set(path.relative(projectDir, testDir).split(path.sep));
if (parts.has('__tests__')) {
Expand Down