From 0e6de2c31dbf8c21277481f112e99c52b913940f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 27 Dec 2017 19:33:54 +0100 Subject: node_modules --- node_modules/ava/lib/snapshot-manager.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'node_modules/ava/lib/snapshot-manager.js') 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); -- cgit v1.2.3