aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ava/lib/snapshot-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ava/lib/snapshot-manager.js')
-rw-r--r--node_modules/ava/lib/snapshot-manager.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/node_modules/ava/lib/snapshot-manager.js b/node_modules/ava/lib/snapshot-manager.js
index ea1246585..fcc24922e 100644
--- a/node_modules/ava/lib/snapshot-manager.js
+++ b/node_modules/ava/lib/snapshot-manager.js
@@ -11,6 +11,7 @@ const indentString = require('indent-string');
const makeDir = require('make-dir');
const md5Hex = require('md5-hex');
const Buffer = require('safe-buffer').Buffer;
+const convertSourceMap = require('convert-source-map');
const concordanceOptions = require('./concordance-options').snapshotManager;
@@ -355,18 +356,39 @@ class Manager {
}
}
-function determineSnapshotDir(projectDir, testDir) {
- const parts = new Set(path.relative(projectDir, testDir).split(path.sep));
+function determineSnapshotDir(options) {
+ const testDir = determineSourceMappedDir(options);
+ if (options.fixedLocation) {
+ const relativeTestLocation = path.relative(options.projectDir, testDir);
+ return path.join(options.fixedLocation, relativeTestLocation);
+ }
+
+ const parts = new Set(path.relative(options.projectDir, testDir).split(path.sep));
if (parts.has('__tests__')) {
return path.join(testDir, '__snapshots__');
- } else if (parts.has('test') || parts.has('tests')) { // Accept tests, even though it's not in the default test patterns
+ }
+ if (parts.has('test') || parts.has('tests')) { // Accept tests, even though it's not in the default test patterns
return path.join(testDir, 'snapshots');
}
+
return testDir;
}
+function determineSourceMappedDir(options) {
+ const source = tryRead(options.file).toString();
+ const converter = convertSourceMap.fromSource(source) || convertSourceMap.fromMapFileSource(source, options.testDir);
+ if (converter) {
+ const map = converter.toObject();
+ const firstSource = `${map.sourceRoot || ''}${map.sources[0]}`;
+ const sourceFile = path.resolve(options.testDir, firstSource);
+ return path.dirname(sourceFile);
+ }
+
+ return options.testDir;
+}
+
function load(options) {
- const dir = determineSnapshotDir(options.projectDir, options.testDir);
+ const dir = determineSnapshotDir(options);
const reportFile = `${options.name}.md`;
const snapFile = `${options.name}.snap`;
const snapPath = path.join(dir, snapFile);