Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'source-map-support' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
function run(testsRoot, clb): any {
// Enable source map support
require("source-map-support").install();
// Read configuration for the coverage file
let coverOptions: ITestRunnerOptions = _readCoverOptions(testsRoot);
if (coverOptions && coverOptions.enabled) {
// Setup coverage pre-test, including post-test hook to report
let coverageRunner = new CoverageRunner(coverOptions, testsRoot, clb);
coverageRunner.setupCoverage();
}
// Glob test files
glob("**/**.test.js", { cwd: testsRoot }, (error, files): any => {
if (error) {
return clb(error);
}
try {
// Fill into Mocha
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var Thing = _interopDefault(require('Thing.js'));
require("source-map-support").install();
global.expect = require('chai').expect;
(function setup() {
beforeEach(function () {
// Setup test things
// In the future we can test multiple different kinds of things!
global.thing1 = {
name: 'Light', // The display name for the thing.
desription: 'An LED light with a basic on/off api.',
// The username of the account you want this device to be added to.
username: 'jake2@gmail.com',
// Properties can be updated by the API
properties: {
state: 'off'
},
beforeEach(function () {
const currentTest = this.currentTest;
chaiJestSnapshot.configureUsingMochaContext(this);
// set up snapshot name
const testFilePath = currentTest.file;
const sourceFilePath = mapSourcePosition({
source: testFilePath,
line: 3,
column: 1,
}).source;
const snapFileName = path.basename(sourceFilePath, path.extname(sourceFilePath)) + ".snap";
chaiJestSnapshot.setFilename(path.join("tests/.snapshots/", snapFileName));
});
export function serverRunner(register) {
// register tests right away on legacy mode
if (server.isLegacy) {
return register();
}
// wrap `self.onerror`,
// remove the annoying warning caused by mocha
wrapErrorEvent();
// avoid polluting client env
require('mocha/mocha');
require('source-map-support/sw-source-map-support').install();
// wait for client request on modern mode
// DON'T use `server.on()`, this listener should be permanently added
self.addEventListener('message', (evt) => {
const {
data,
ports,
} = evt;
if (data && data.request === 'MOCHA_TASKS') {
ports[0].postMessage({
suites: runTests(register),
});
}
});
}
export function frameToString(frame)
{
const wrappedFrame = wrapCallSite(frame)
var sourceFile = wrappedFrame.getFileName()
var functionName = wrappedFrame.getFunctionName()
var typeName = wrappedFrame.getTypeName()
// Ignore some cryptic function names which typically are just function calls
if (FUNCTION_NAME_CLEARANCE.some((regexp) => regexp.test(functionName))) {
functionName = ""
}
// Filter out configured type names
if (TYPE_NAME_CLEARANCE.some((regexp) => regexp.test(typeName))) {
typeName = ""
}
// Strip out generated filename part from source field
export function frameToString(frame)
{
const wrappedFrame = wrapCallSite(frame)
var sourceFile = wrappedFrame.getFileName()
var functionName = wrappedFrame.getFunctionName()
var typeName = wrappedFrame.getTypeName()
// Ignore some cryptic function names which typically are just function calls
if (FUNCTION_NAME_CLEARANCE.some((regexp) => regexp.test(functionName))) {
functionName = ""
}
// Filter out configured type names
if (TYPE_NAME_CLEARANCE.some((regexp) => regexp.test(typeName))) {
typeName = ""
}
// Strip out generated filename part from source field
export function isRelevantFrame(frame) {
const wrappedFrame = wrapCallSite(frame);
const generatedFile = frame.getFileName();
const sourceFile = wrappedFrame.getFileName();
const functionName = wrappedFrame.getFunctionName();
// Filter out all raw files which do not have any source mapping
// This typically removes most of the build related infrastructure
// which is neither application or framework code.
const isCompiled = sourceFile !== generatedFile;
if (!isCompiled) {
return false;
}
// Filter out specific functions e.g. webpack require wrappers
if (FUNCTION_NAME_FILTERS.some(regexp => regexp.test(functionName))) {
return false;
export function isRelevantFrame(frame)
{
const wrappedFrame = wrapCallSite(frame)
const generatedFile = frame.getFileName()
var sourceFile = wrappedFrame.getFileName()
var functionName = wrappedFrame.getFunctionName()
// Filter out all raw files which do not have any source mapping
// This typically removes most of the build related infrastructure
// which is neither application or framework code.
const isCompiled = sourceFile !== generatedFile
if (!isCompiled) {
return false
}
// Filter out specific functions e.g. webpack require wrappers
if (FUNCTION_NAME_FILTERS.some((regexp) => regexp.test(functionName))) {
return false
context.coverage.cov.files = context.coverage.cov.files.map(async (file) => {
if (!file.sourcemaps) {
// return untouched file
return file;
}
const descriptors = {};
const generatedContent = Object.keys(file.source).map((k) => file.source[k].source).join('\n');
// Rather than relying on generated content, get the nodes tree from sourcemap consumer
const sourcemap = SourceMapSupport.retrieveSourceMap(file.filename).map;
const smc = await new SourceMapConsumer(sourcemap);
// For each original files that might have been transformed into this generate content, store a new descriptor
SourceNode.fromStringWithSourceMap(generatedContent, smc).walkSourceContents((sourceFile, content) => {
descriptors[sourceFile] = {
generated: file.filename,
filename: sourceFile,
source: {}
};
content.split('\n').forEach((line, number) => {
descriptors[sourceFile].source[number + 1] = {
source: line,
// consider line covered by default
const ret = {
// Ensure folder separator to be url-friendly
filename: filename.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''),
percent: 0,
hits: 0,
misses: 0,
sloc: data.sloc,
source: {},
externals: internals.external(filename)
};
// Use sourcemap consumer rather than SourceMapSupport.mapSourcePosition itself which perform path transformations
let sourcemap = null;
if (options.sourcemaps) {
sourcemap = SourceMapSupport.retrieveSourceMap(ret.filename);
if (!sourcemap) {
const smre = /\/\/\#.*data:application\/json[^,]+base64,.*\r?\n?$/;
let sourceIndex = data.source.length - 1;
while (sourceIndex >= 0 && !smre.test(data.source[sourceIndex])) {
sourceIndex--;
}
if (sourceIndex >= 0) {
const re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
let lastMatch;
let match;
while (match = re.exec(data.source[sourceIndex])) {
lastMatch = match;
}
sourcemap = {