How to use relativeToSandbox method in stryker-parent

Best JavaScript code snippet using stryker-parent

PackageEnvironment.js

Source:PackageEnvironment.js Github

copy

Full Screen

...75 * if a location is actually a symlink to somewhere in the sandbox, but encode76 * the path (including symlinks) if it points outside the sandbox. I believe77 * that will work with tar --dereference.78 */79function relativeToSandbox(realFromPath, toPath) {80 /**81 * This sucks. If there's a symlink pointing outside of the sandbox, the82 * script can't include those, so it gives it from perspective of symlink.83 * This will work with tar, but there could be issues if multiple symlink84 * links all point to the same location, but appear to be different. We85 * should execute a warning here instead. This problem is far from solved.86 * What would tar even do in that situation if it's following symlinks87 * outside of the tar directory? Would it copy it multiple times or copy it88 * once somehow?89 */90 let realToPath = fs.realpathSync(toPath);91 let toPathToUse = pathIsInside(realFromPath, realToPath)92 ? realToPath93 : toPath;94 let ret = path.relative(realFromPath, toPathToUse);95 return (ret == '0') ? "$esy__sandbox" : `$esy__sandbox/${ret}`;96}97function getScopes(config) {98 if (!config.scope) {99 return {};100 }101 var scopes = (config.scope || '').split('|');102 var scopeObj = {};103 for (var i = 0; i < scopes.length; i++) {104 scopeObj[scopes[i]] = true;105 }106 return scopeObj;107}108/**109 * Validates env vars that were configured in package.json as opposed to110 * automatically created.111 */112var validatePackageJsonExportedEnvVar = (envVar, config, inPackageName, envVarConfigPrefix) => {113 let beginsWithPackagePrefix = envVar.indexOf(envVarConfigPrefix) === 0;114 var ret = [];115 if (config.scopes !== undefined) {116 ret.push(117 envVar + " has a field 'scopes' (plural). You probably meant 'scope'. " +118 "The owner of " + inPackageName + " likely made a mistake"119 );120 }121 let scopeObj = getScopes(config);122 if (!scopeObj.global) {123 if (!beginsWithPackagePrefix) {124 if (envVar.toUpperCase().indexOf(envVarConfigPrefix) === 0) {125 ret.push(126 "It looks like " + envVar + " is trying to be configured as a package scoped variable, " +127 "but it has the wrong capitalization. It should begin with " + envVarConfigPrefix +128 ". The owner of " + inPackageName + " likely made a mistake"129 );130 } else {131 ret.push(132 "Environment variable " + envVar + " " +133 "doesn't begin with " + envVarConfigPrefix + " but it is not marked as 'global'. " +134 "You should either prefix variables with " + envVarConfigPrefix + " or make them global." +135 "The author of " + inPackageName + " likely made a mistake"136 );137 }138 }139 } else {140 // Else, it's global, but better not be trying to step on another package!141 if (!beginsWithPackagePrefix && envVar.indexOf("__") !== -1) {142 ret.push(143 envVar +144 " looks like it's trying to step on another " +145 "package because it has a double underscore - which is how we express namespaced env vars. " +146 "The package owner for " + inPackageName + " likely made a mistake"147 );148 }149 }150 return ret;151};152function builtInsPerPackage(153 sandbox: Sandbox,154 prefix: string,155 packageInfo: PackageInfo,156 installDirectory?: string157) {158 let {159 packageJson: {name, version, esy},160 rootDirectory,161 dependencyTree,162 } = packageInfo;163 let isRootPackage = name === sandbox.packageInfo.packageJson.name;164 function builtIn(val) {165 return {166 __BUILT_IN_DO_NOT_USE_OR_YOU_WILL_BE_PIPd: true,167 global: false,168 exclusive: true,169 val,170 }171 }172 return {173 [`${prefix}__name`]: builtIn(174 name175 ),176 [`${prefix}__version`]: builtIn(177 version || null178 ),179 [`${prefix}__root`]: builtIn(180 esy.buildsInSource181 ? targetPath(sandbox, packageInfo, '_build')182 : relativeToSandbox(sandbox.packageInfo.rootDirectory, rootDirectory)183 ),184 [`${prefix}__depends`]: builtIn(185 Object.keys(dependencyTree).join(' ')186 ),187 [`${prefix}__target_dir`]: builtIn(188 targetPath(sandbox, packageInfo, '_build')189 ),190 [`${prefix}__install`]: builtIn(191 installDirectory != null192 ? installDirectory193 : targetPath(sandbox, packageInfo, '_install')194 ),195 [`${prefix}__bin`]: builtIn(196 `$${prefix}__install/bin`197 ),198 [`${prefix}__sbin`]: builtIn(199 `$${prefix}__install/sbin`200 ),201 [`${prefix}__lib`]: builtIn(202 `$${prefix}__install/lib`203 ),204 [`${prefix}__man`]: builtIn(205 `$${prefix}__install/man`206 ),207 [`${prefix}__doc`]: builtIn(208 `$${prefix}__install/doc`209 ),210 [`${prefix}__stublibs`]: builtIn(211 `$${prefix}__install/stublibs`212 ),213 [`${prefix}__toplevel`]: builtIn(214 `$${prefix}__install/toplevel`215 ),216 [`${prefix}__share`]: builtIn(217 `$${prefix}__install/share`218 ),219 [`${prefix}__etc`]: builtIn(220 `$${prefix}__install/etc`221 ),222 };223}224function addEnvConfigForPackage(225 {seenVars, errors, normalizedEnvVars}: EnvironmentConfigState,226 realPathSandboxRootOnEjectingHost,227 packageName,228 packageJsonFilePath,229 exportedEnv230) {231 var nextSeenVars = {};232 var nextErrors = []233 var nextNormalizedEnvVars = [];234 for (var envVar in exportedEnv) {235 var config = exportedEnv[envVar];236 nextNormalizedEnvVars.push({237 name: envVar,238 value: config.val,239 automaticDefault: !!config.__BUILT_IN_DO_NOT_USE_OR_YOU_WILL_BE_PIPd240 })241 // The seenVars will only cover the cases when another package declares the242 // variable, not when it's loaded from your bashrc etc.243 if (seenVars[envVar] && seenVars[envVar].config.exclusive) {244 nextErrors.push(245 (seenVars[envVar].config.__BUILT_IN_DO_NOT_USE_OR_YOU_WILL_BE_PIPd ? 'Built-in variable ' : '') +246 envVar +247 " has already been set by " + relativeToSandbox(realPathSandboxRootOnEjectingHost, seenVars[envVar].packageJsonPath) + " " +248 "which configured it with exclusive:true. That means it wants to be the only one to set it. Yet " +249 packageName + " is trying to override it."250 );251 }252 if (seenVars[envVar] && (config.exclusive)) {253 nextErrors.push(254 envVar +255 " has already been set by " + relativeToSandbox(realPathSandboxRootOnEjectingHost, seenVars[envVar].packageJsonPath) + " " +256 "and " + packageName + " has configured it with exclusive:true. " +257 "Sometimes you can reduce the likehood of conflicts by marking some packages as buildTimeOnlyDependencies."258 );259 }260 nextSeenVars[envVar] = {261 packageJsonPath: packageJsonFilePath || 'unknownPackage',262 config263 };264 }265 return {266 errors: errors.concat(nextErrors),267 seenVars: extend(seenVars, nextSeenVars),268 normalizedEnvVars: normalizedEnvVars.concat(nextNormalizedEnvVars)269 };270}271function computeEnvVarsForPackage(272 sandbox: Sandbox,273 packageInfo: PackageInfo274) {275 let {rootDirectory, packageJson, normalizedName} = packageInfo;276 var packageJsonDir = path.dirname(rootDirectory);277 var packageName = packageJson.name;278 var envVarConfigPrefix = normalizedName;279 let errors = [];280 var autoExportedEnvVarsForPackage = builtInsPerPackage(281 sandbox,282 envVarConfigPrefix,283 packageInfo284 );285 let {286 seenVars,287 errors: nextErrors,288 normalizedEnvVars289 } = addEnvConfigForPackage(290 {seenVars: globalSeenVars, errors, normalizedEnvVars: []},291 sandbox.packageInfo.rootDirectory,292 packageName,293 rootDirectory,294 autoExportedEnvVarsForPackage295 );296 for (var envVar in packageJson.esy.exportedEnv) {297 nextErrors = nextErrors.concat(298 validatePackageJsonExportedEnvVar(299 envVar,300 packageJson.esy.exportedEnv[envVar],301 packageName,302 envVarConfigPrefix303 )304 );305 }306 let {307 seenVars: nextSeenVars,308 errors: nextNextErrors,309 normalizedEnvVars: nextNormalizedEnvVars310 } = addEnvConfigForPackage(311 {seenVars, errors: nextErrors, normalizedEnvVars},312 sandbox.packageInfo.rootDirectory,313 packageName,314 path.join(rootDirectory, 'package.json'),315 packageJson.esy.exportedEnv316 );317 /**318 * Update the global. Yes, we tried to be as functional as possible aside319 * from this.320 */321 globalSeenVars = nextSeenVars;322 globalGroups.push({323 root: relativeToSandbox(324 sandbox.packageInfo.rootDirectory,325 rootDirectory326 ),327 packageJsonPath: relativeToSandbox(328 sandbox.packageInfo.rootDirectory,329 path.join(rootDirectory, 'package.json')330 ),331 packageJson: packageJson,332 envVars: nextNormalizedEnvVars,333 errors: nextNextErrors334 })335}336function targetPath(sandbox, packageInfo, tree: '_install' | '_build', ...path) {337 let packageName = packageInfo.packageJson.name;338 let packageKey = packageInfoKey(sandbox.env, packageInfo);339 let isRootPackage = packageName === sandbox.packageInfo.packageJson.name;340 if (isRootPackage) {341 return ['$esy__sandbox', tree, ...path].join('/');...

Full Screen

Full Screen

ts-config-preprocessor.ts

Source:ts-config-preprocessor.ts Github

copy

Full Screen

1import path from 'path';2import { StrykerOptions, File } from '@stryker-mutator/api/core';3import { tokens, commonTokens } from '@stryker-mutator/api/plugin';4import { Logger } from '@stryker-mutator/api/logging';5import { FilePreprocessor } from './file-preprocessor';6interface TSConfigReferences {7 references?: Array<{ path: string }>;8 extends?: string;9}10/**11 * A helper class that rewrites `references` and `extends` file paths if they end up falling outside of the sandbox.12 * @example13 * {14 * "extends": "../../tsconfig.settings.json",15 * "references": {16 * "path": "../model"17 * }18 * }19 * becomes:20 * {21 * "extends": "../../../../tsconfig.settings.json",22 * "references": {23 * "path": "../../../model"24 * }25 * }26 */27export class TSConfigPreprocessor implements FilePreprocessor {28 private readonly touched: string[] = [];29 private readonly fs = new Map<string, File>();30 public static readonly inject = tokens(commonTokens.logger, commonTokens.options);31 constructor(private readonly log: Logger, private readonly options: StrykerOptions) {}32 public async preprocess(input: File[]): Promise<File[]> {33 if (this.options.inPlace) {34 // If stryker is running 'inPlace', we don't have to change the tsconfig file35 return input;36 } else {37 const tsconfigFile = path.resolve(this.options.tsconfigFile);38 if (input.find((file) => file.name === tsconfigFile)) {39 this.fs.clear();40 input.forEach((file) => {41 this.fs.set(file.name, file);42 });43 await this.rewriteTSConfigFile(tsconfigFile);44 return [...this.fs.values()];45 } else {46 return input;47 }48 }49 }50 private async rewriteTSConfigFile(tsconfigFileName: string): Promise<void> {51 if (!this.touched.includes(tsconfigFileName)) {52 this.touched.push(tsconfigFileName);53 const tsconfigFile = this.fs.get(tsconfigFileName);54 if (tsconfigFile) {55 this.log.debug('Rewriting file %s', tsconfigFile);56 const ts = await import('typescript');57 const { config }: { config?: TSConfigReferences } = ts.parseConfigFileTextToJson(tsconfigFile.name, tsconfigFile.textContent);58 if (config) {59 await this.rewriteExtends(config, tsconfigFileName);60 await this.rewriteProjectReferences(config, tsconfigFileName);61 this.fs.set(tsconfigFileName, new File(tsconfigFileName, JSON.stringify(config, null, 2)));62 }63 }64 }65 }66 private async rewriteExtends(config: TSConfigReferences, tsconfigFileName: string): Promise<boolean> {67 const extend = config.extends;68 if (typeof extend === 'string') {69 const extendsFileName = path.resolve(path.dirname(tsconfigFileName), extend);70 const relativeToSandbox = path.relative(process.cwd(), extendsFileName);71 if (relativeToSandbox.startsWith('..')) {72 config.extends = this.join('..', '..', extend);73 return true;74 } else {75 await this.rewriteTSConfigFile(extendsFileName);76 }77 }78 return false;79 }80 private async rewriteProjectReferences(config: TSConfigReferences, originTSConfigFileName: string): Promise<void> {81 const ts = await import('typescript');82 if (Array.isArray(config.references)) {83 for (const reference of config.references) {84 const referencePath = ts.resolveProjectReferencePath(reference);85 const referencedProjectFileName = path.resolve(path.dirname(originTSConfigFileName), referencePath);86 const relativeToProject = path.relative(process.cwd(), referencedProjectFileName);87 if (relativeToProject.startsWith('..')) {88 reference.path = this.join('..', '..', referencePath);89 } else {90 await this.rewriteTSConfigFile(referencedProjectFileName);91 }92 }93 }94 }95 private join(...pathSegments: string[]) {96 return pathSegments.map((segment) => segment.replace(/\\/g, '/')).join('/');97 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var path = stryker.relativeToSandbox('test.js');3console.log(path);4var stryker = require('stryker');5var path = stryker.relativeToSandbox('test.js');6console.log(path);7var stryker = require('stryker-api');8var path = stryker.relativeToSandbox('test.js');9console.log(path);10var stryker = require('stryker');11var path = stryker.relativeToSandbox('test.js');12console.log(path);13var stryker = require('stryker');14var path = stryker.relativeToSandbox('test.js');15console.log(path);16var stryker = require('stryker');17var path = stryker.relativeToSandbox('test.js');18console.log(path);19var stryker = require('stryker');20var path = stryker.relativeToSandbox('test.js');21console.log(path);22var stryker = require('stryker');23var path = stryker.relativeToSandbox('test.js');24console.log(path);25var stryker = require('stryker');26var path = stryker.relativeToSandbox('test.js');27console.log(path);28var stryker = require('stryker');29var path = stryker.relativeToSandbox('test.js');30console.log(path);31var stryker = require('stryker');

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const path = require('path');3const pathToSandbox = strykerParent.relativeToSandbox('sandbox');4console.log(`Path to sandbox: ${pathToSandbox}`);5const strykerParent = require('stryker-parent');6const path = require('path');7const pathToRoot = strykerParent.relativeToRoot('test.js');8console.log(`Path to root: ${pathToRoot}`);9const Stryker = require('stryker-api/core').Stryker;10const stryker = new Stryker({11});12stryker.runMutationTest()13 .then(() => {14 console.log('Done!');15 })16 .catch((error) => {17 console.log(error);18 });19module.exports = function(config) {20 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { relativeToSandbox } = require('stryker-parent');3const testFile = relativeToSandbox('test.js');4const testFile2 = relativeToSandbox('test2.js');5console.log(testFile);6console.log(testFile2);7const path = require('path');8const { relativeToSandbox } = require('stryker-parent');9const testFile = relativeToSandbox('test.js');10const testFile2 = relativeToSandbox('test2.js');11console.log(testFile);12console.log(testFile2);13module.exports = function(config) {14 config.set({15 jest: {16 },17 });18};

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var stryker = require('stryker-parent');3var sandbox = stryker.relativeToSandbox('sandbox');4var sandboxedFile = path.join(sandbox, 'file.js');5console.log(sandboxedFile);6### `relativeToSandbox(relativePath)`7### `relativeToRoot(relativePath)`

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var path = require('path');3var test = parent.relativeToSandbox('test.js');4var test2 = parent.relativeToSandbox('test2.js');5var test3 = parent.relativeToSandbox(path.join('subdir', 'test3.js'));6var test4 = parent.relativeToSandbox(path.join('subdir', 'test4.js'));7var test5 = parent.relativeToSandbox(path.join('subdir', 'test5.js'));8var test6 = parent.relativeToSandbox(path.join('subdir', 'test6.js'));9var test7 = parent.relativeToSandbox(path.join('subdir', 'test7.js'));10var test8 = parent.relativeToSandbox(path.join('subdir', 'test8.js'));11var test9 = parent.relativeToSandbox(path.join('subdir', 'test9.js'));12var test10 = parent.relativeToSandbox(path.join('subdir', 'test10.js'));13var test11 = parent.relativeToSandbox(path.join('subdir', 'test11.js'));14var test12 = parent.relativeToSandbox(path.join('subdir', 'test12.js'));15var test13 = parent.relativeToSandbox(path.join('subdir', 'test13.js'));16var test14 = parent.relativeToSandbox(path.join('subdir', 'test14.js'));17var test15 = parent.relativeToSandbox(path.join('subdir', 'test15.js'));18var test16 = parent.relativeToSandbox(path.join('subdir', 'test16.js'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { relativeToSandbox } = require('stryker-parent');2const { relative } = require('path');3const path = relativeToSandbox('some/file.js');4const path2 = relativeToSandbox('some/other/file.js');5const path3 = relativeToSandbox('some/other/file.js');6console.log(path);7console.log(path2);8console.log(path3);9const { relativeToSandbox } = require('stryker-parent');10const { relative } = require('path');11const path = relativeToSandbox('other/file.js');12const path2 = relativeToSandbox('other/file.js');13const path3 = relativeToSandbox('other/file.js');14console.log(path);15console.log(path2);16console.log(path3);17const { relativeToSandbox } = require('stryker-parent');18const { relative } = require('path');19const path = relativeToSandbox('file.js');20const path2 = relativeToSandbox('file.js');21const path3 = relativeToSandbox('file.js');22console.log(path);23console.log(path2);24console.log(path3);25const { relativeToSandbox } = require('stryker-parent');26const { relative } = require('path');27const path = relativeToSandbox('other/file.js');28const path2 = relativeToSandbox('other/file.js');29const path3 = relativeToSandbox('other/file.js');30console.log(path);31console.log(path2);32console.log(path3);

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var relativeToSandbox = require('stryker-parent').relativeToSandbox;3var path = relativeToSandbox('src/app');4Stryker 0.7.0 is a major release that adds support for running your tests in a sandbox. This means that your tests can no longer access the file system, which means you can't use `fs` or `require` to load files. This is a huge step forward in terms of security, but it also means that you need to change your tests a bit. The most important thing to know is that you can no longer use `require` to load files from your project. Instead, you can use the `relativeToSandbox` function to get the path to a file in your project. The `relativeToSandbox` function is provided by the `stryker-parent` package. You can install it with `npm install stryker-parent --save-dev`. You can use it like this:5var path = require('path');6var relativeToSandbox = require('stryker-parent').relativeToSandbox;7var path = relativeToSandbox('src/app');

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var strykerParent = require('stryker-parent');3module.exports = function (config) {4 config.set({5 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },6 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestFramework.js'), mutated: false, included: false },7 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineReporter.js'), mutated: false, included: false },8 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestAdapter.js'), mutated: false, included: false },9 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestResult.js'), mutated: false, included: false },10 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },11 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },12 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },13 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },14 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },15 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/JasmineTestRunner.js'), mutated: false, included: false },16 { pattern: strykerParent.relativeToSandbox('node_modules/stryker-jasmine-runner/src/Jasmine

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful