diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-12-27 19:33:54 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-12-27 19:34:16 +0100 |
commit | 0e6de2c31dbf8c21277481f112e99c52b913940f (patch) | |
tree | 91789032de3b8eec9d789acd1323f25fc5d08422 /node_modules/ava/lib/snapshot-manager.js | |
parent | ceda0da31ad542c598c68146ae0712ca03df3d71 (diff) | |
download | wallet-core-0e6de2c31dbf8c21277481f112e99c52b913940f.tar.xz |
node_modules
Diffstat (limited to 'node_modules/ava/lib/snapshot-manager.js')
-rw-r--r-- | node_modules/ava/lib/snapshot-manager.js | 30 |
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); |