@web/test-runner-core
Advanced tools
Comparing version 0.10.4 to 0.10.5
# @web/test-runner-core | ||
## 0.10.5 | ||
### Patch Changes | ||
- ad815710: fetch source map from server when generating code coverage reports. this fixes errors when using build tools that generate source maps on the fly, which don't exist on the file system | ||
- c4738a40: support non-inline source maps for stack traces | ||
## 0.10.4 | ||
@@ -4,0 +11,0 @@ |
@@ -22,2 +22,3 @@ export { CoverageMapData } from 'istanbul-lib-coverage'; | ||
export { isTestFilePath } from './utils/isTestFilePath'; | ||
export { fetchSourceMap } from './utils/fetchSourceMap'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isTestFilePath = exports.EventEmitter = exports.SESSION_STATUS = exports.TestSessionManager = exports.BufferedLogger = exports.TestRunnerCli = exports.TestRunner = exports.constants = void 0; | ||
exports.fetchSourceMap = exports.isTestFilePath = exports.EventEmitter = exports.SESSION_STATUS = exports.TestSessionManager = exports.BufferedLogger = exports.TestRunnerCli = exports.TestRunner = exports.constants = void 0; | ||
const constants = __importStar(require("./utils/constants")); | ||
@@ -40,2 +40,4 @@ exports.constants = constants; | ||
Object.defineProperty(exports, "isTestFilePath", { enumerable: true, get: function () { return isTestFilePath_1.isTestFilePath; } }); | ||
var fetchSourceMap_1 = require("./utils/fetchSourceMap"); | ||
Object.defineProperty(exports, "fetchSourceMap", { enumerable: true, get: function () { return fetchSourceMap_1.fetchSourceMap; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -7,41 +7,12 @@ "use strict"; | ||
exports.createSourceMapFunction = void 0; | ||
const path_1 = require("path"); | ||
const convert_source_map_1 = __importDefault(require("convert-source-map")); | ||
const path_1 = __importDefault(require("path")); | ||
const source_map_1 = require("source-map"); | ||
const path_2 = __importDefault(require("path")); | ||
const request_1 = require("./request"); | ||
/** | ||
* Fetches the source maps for a file by retreiving the original source code from the server, and | ||
* reading the source maps if there are any available. | ||
*/ | ||
async function fetchSourceMap(protocol, host, port, browserUrl, filePath, userAgent) { | ||
// fetch the source code used by the browser, using the browser's user agent to | ||
// account for accurate transformation | ||
const { body } = await request_1.request({ | ||
protocol, | ||
host, | ||
path: encodeURI(browserUrl), | ||
port: String(port), | ||
method: 'GET', | ||
headers: { 'user-agent': userAgent }, | ||
}); | ||
// we couldn't retreive this file, this could be because it is a generated file | ||
// from a server plugin which no longer exists | ||
if (!body) { | ||
return; | ||
const fetchSourceMap_1 = require("../../../utils/fetchSourceMap"); | ||
function resolveRelativeTo(relativeTo, filePath) { | ||
if (path_1.default.isAbsolute(filePath)) { | ||
return filePath; | ||
} | ||
const sourceMap = | ||
// inline source map | ||
convert_source_map_1.default.fromSource(body) || | ||
// external source map | ||
convert_source_map_1.default.fromMapFileSource(body, path_1.dirname(filePath)); | ||
return sourceMap !== null && sourceMap !== void 0 ? sourceMap : undefined; | ||
const dir = path_1.default.dirname(relativeTo); | ||
return path_1.default.join(dir, filePath); | ||
} | ||
function resolveRelativeTo(relativeTo, path) { | ||
const dir = path_1.dirname(relativeTo); | ||
if (path.startsWith(dir)) { | ||
return path; | ||
} | ||
return path_1.join(dir, path); | ||
} | ||
/** | ||
@@ -71,3 +42,5 @@ * Creates a function that can map file path, line an column based on source maps. It maintains a cache of source maps, | ||
} | ||
cached = {}; | ||
else { | ||
cached = {}; | ||
} | ||
cachedSourceMaps.set(cacheKey, cached); | ||
@@ -86,12 +59,20 @@ // get the raw source map, from cache or new | ||
cached.loadingPromise = loadingPromise; | ||
const result = await fetchSourceMap(protocol, host, port, browserUrl, filePath, userAgent); | ||
cached.sourceMap = result; | ||
resolveLoading(); | ||
if (!result) { | ||
return null; | ||
try { | ||
const result = await fetchSourceMap_1.fetchSourceMap({ | ||
protocol, | ||
host, | ||
port, | ||
browserUrl, | ||
userAgent, | ||
}); | ||
sourceMap = result.sourceMap; | ||
cached.sourceMap = sourceMap; | ||
} | ||
else { | ||
sourceMap = result; | ||
finally { | ||
resolveLoading(); | ||
} | ||
} | ||
if (!sourceMap) { | ||
return null; | ||
} | ||
// if there is no line and column we're looking for just the associated file, for example | ||
@@ -139,3 +120,3 @@ // the test file itself has source maps. if this is a single file source map, we can return | ||
} | ||
const newFilePath = originalPosition.source.split('/').join(path_2.default.sep); | ||
const newFilePath = originalPosition.source.split('/').join(path_1.default.sep); | ||
return { | ||
@@ -149,3 +130,4 @@ filePath: resolveRelativeTo(filePath, newFilePath), | ||
catch (error) { | ||
console.error(error.message); | ||
console.error(`Error while reading source maps for ${filePath}`); | ||
console.error(error); | ||
return null; | ||
@@ -152,0 +134,0 @@ } |
@@ -15,5 +15,11 @@ "use strict"; | ||
await Promise.all([ | ||
parseBrowserLogs_1.parseBrowserLogs(config, mapBrowserUrl, mapStackLocation, result), | ||
parseBrowserErrors_1.parseSessionErrors(config, mapBrowserUrl, mapStackLocation, result), | ||
parseBrowserErrors_1.parseTestResults(config, mapBrowserUrl, mapStackLocation, result), | ||
parseBrowserLogs_1.parseBrowserLogs(config, mapBrowserUrl, mapStackLocation, result).catch(error => { | ||
console.error(error); | ||
}), | ||
parseBrowserErrors_1.parseSessionErrors(config, mapBrowserUrl, mapStackLocation, result).catch(error => { | ||
console.error(error); | ||
}), | ||
parseBrowserErrors_1.parseTestResults(config, mapBrowserUrl, mapStackLocation, result).catch(error => { | ||
console.error(error); | ||
}), | ||
]); | ||
@@ -20,0 +26,0 @@ return result; |
{ | ||
"name": "@web/test-runner-core", | ||
"version": "0.10.4", | ||
"version": "0.10.5", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -40,1 +40,2 @@ export { CoverageMapData } from 'istanbul-lib-coverage'; | ||
export { isTestFilePath } from './utils/isTestFilePath'; | ||
export { fetchSourceMap } from './utils/fetchSourceMap'; |
@@ -1,7 +0,6 @@ | ||
import { dirname, join } from 'path'; | ||
import convertSourceMap, { SourceMapConverter } from 'convert-source-map'; | ||
import path from 'path'; | ||
import { SourceMapConverter } from 'convert-source-map'; | ||
import { SourceMapConsumer } from 'source-map'; | ||
import path from 'path'; | ||
import { request } from './request'; | ||
import { fetchSourceMap } from '../../../utils/fetchSourceMap'; | ||
import { StackLocation } from '@web/browser-logs'; | ||
@@ -20,47 +19,10 @@ | ||
/** | ||
* Fetches the source maps for a file by retreiving the original source code from the server, and | ||
* reading the source maps if there are any available. | ||
*/ | ||
async function fetchSourceMap( | ||
protocol: string, | ||
host: string, | ||
port: number, | ||
browserUrl: string, | ||
filePath: string, | ||
userAgent: string, | ||
) { | ||
// fetch the source code used by the browser, using the browser's user agent to | ||
// account for accurate transformation | ||
const { body } = await request({ | ||
protocol, | ||
host, | ||
path: encodeURI(browserUrl), | ||
port: String(port), | ||
method: 'GET', | ||
headers: { 'user-agent': userAgent }, | ||
}); | ||
// we couldn't retreive this file, this could be because it is a generated file | ||
// from a server plugin which no longer exists | ||
if (!body) { | ||
return; | ||
function resolveRelativeTo(relativeTo: string, filePath: string): string { | ||
if (path.isAbsolute(filePath)) { | ||
return filePath; | ||
} | ||
const sourceMap = | ||
// inline source map | ||
convertSourceMap.fromSource(body) || | ||
// external source map | ||
convertSourceMap.fromMapFileSource(body, dirname(filePath)); | ||
return sourceMap ?? undefined; | ||
const dir = path.dirname(relativeTo); | ||
return path.join(dir, filePath); | ||
} | ||
function resolveRelativeTo(relativeTo: string, path: string) { | ||
const dir = dirname(relativeTo); | ||
if (path.startsWith(dir)) { | ||
return path; | ||
} | ||
return join(dir, path); | ||
} | ||
/** | ||
@@ -94,8 +56,9 @@ * Creates a function that can map file path, line an column based on source maps. It maintains a cache of source maps, | ||
} | ||
} else { | ||
cached = {}; | ||
} | ||
cached = {}; | ||
cachedSourceMaps.set(cacheKey, cached); | ||
// get the raw source map, from cache or new | ||
let sourceMap: SourceMapConverter; | ||
let sourceMap: SourceMapConverter | undefined; | ||
if (cached.sourceMap) { | ||
@@ -111,12 +74,19 @@ sourceMap = cached?.sourceMap; | ||
const result = await fetchSourceMap(protocol, host, port, browserUrl, filePath, userAgent); | ||
cached.sourceMap = result; | ||
resolveLoading!(); | ||
if (!result) { | ||
return null; | ||
} else { | ||
sourceMap = result; | ||
try { | ||
const result = await fetchSourceMap({ | ||
protocol, | ||
host, | ||
port, | ||
browserUrl, | ||
userAgent, | ||
}); | ||
sourceMap = result.sourceMap; | ||
cached.sourceMap = sourceMap; | ||
} finally { | ||
resolveLoading!(); | ||
} | ||
} | ||
if (!sourceMap) { | ||
return null; | ||
} | ||
@@ -177,3 +147,4 @@ // if there is no line and column we're looking for just the associated file, for example | ||
} catch (error) { | ||
console.error(error.message); | ||
console.error(`Error while reading source maps for ${filePath}`); | ||
console.error(error); | ||
return null; | ||
@@ -180,0 +151,0 @@ } |
@@ -26,7 +26,13 @@ import { MapStackLocation, StackLocation } from '@web/browser-logs'; | ||
await Promise.all([ | ||
parseBrowserLogs(config, mapBrowserUrl, mapStackLocation, result), | ||
parseSessionErrors(config, mapBrowserUrl, mapStackLocation, result), | ||
parseTestResults(config, mapBrowserUrl, mapStackLocation, result), | ||
parseBrowserLogs(config, mapBrowserUrl, mapStackLocation, result).catch(error => { | ||
console.error(error); | ||
}), | ||
parseSessionErrors(config, mapBrowserUrl, mapStackLocation, result).catch(error => { | ||
console.error(error); | ||
}), | ||
parseTestResults(config, mapBrowserUrl, mapStackLocation, result).catch(error => { | ||
console.error(error); | ||
}), | ||
]); | ||
return result; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
403129
254
6874