Best JavaScript code snippet using stryker-parent
pickupUnusedExports.ts
Source:pickupUnusedExports.ts
1import * as ts from 'typescript';2import * as path from 'path';34import ExportData from '../types/ExportData';5import ExportDataMap from '../types/ExportDataMap';6import ImportsAndExports from '../types/ImportsAndExports';7import resolveModule from '../packer/resolveModule';8import isEqualPath from '../utils/isEqualPath';910function cloneExportData(data: ExportData[]): ExportData[] {11 return data.map((x) => {12 return {13 baseName: x.baseName,14 moduleName: x.moduleName,15 node: x.node,16 namedExports: x.namedExports.map((named) => {17 return {18 name: named.name,19 baseName: named.baseName,20 node: named.node21 } as typeof named;22 })23 } as ExportData;24 });25}2627export default function pickupUnusedExports(28 entryFile: string,29 entryExport: string | undefined,30 allData: { [fileName: string]: ImportsAndExports },31 host: ts.CompilerHost,32 compilerOptions: ts.CompilerOptions,33 resolutionCache: ts.ModuleResolutionCache34): ExportDataMap {35 const ret: ExportDataMap = {};36 Object.keys(allData).forEach((fileName) => {37 if (isEqualPath(entryFile, fileName)) {38 entryFile = fileName;39 }40 ret[fileName] = cloneExportData(allData[fileName]!.exports);41 });4243 const usedDataFileNames: string[] = [];44 const usedDataExports: ExportDataMap = {};4546 const processUsingData = (targetFileName: string, fromName: string | undefined): boolean => {47 const d = ret[targetFileName];48 if (!d) {49 return false;50 }51 if (typeof (fromName) === 'undefined' || fromName === '*') {52 // all exports are 'used'53 usedDataFileNames.push(targetFileName);54 usedDataExports[targetFileName] = d;55 ret[targetFileName] = [];56 return true;57 } else {58 for (let i = d.length - 1; i >= 0; --i) {59 const x = d[i];60 let usedExports: typeof x.namedExports = [];61 for (let j = x.namedExports.length - 1; j >= 0; --j) {62 const named = x.namedExports[j];63 if (named.name === fromName) {64 usedExports = usedExports.concat(x.namedExports.splice(j, 1));65 //break;66 }67 }68 if (usedExports.length > 0) {69 const base = usedDataExports[targetFileName];70 if (!x.namedExports.length) {71 const a = d.splice(i, 1);72 a[0].namedExports = usedExports;73 if (base) {74 usedDataExports[targetFileName] = base.concat(a);75 } else {76 usedDataFileNames.push(targetFileName);77 usedDataExports[targetFileName] = a78 }79 } else {80 const newData = {81 moduleName: x.moduleName,82 baseName: x.baseName,83 node: x.node,84 namedExports: usedExports85 };86 if (base) {87 usedDataExports[targetFileName] = base.concat(newData);88 } else {89 usedDataFileNames.push(targetFileName);90 usedDataExports[targetFileName] = [newData];91 }92 }93 return true;94 }95 }96 return false;97 }98 };99100 if (!processUsingData(entryFile, entryExport)) {101 return {};102 }103104 let lastUsedDataKeyIndex = 0;105 while (true) {106 let changed = false;107 let i = lastUsedDataKeyIndex;108 lastUsedDataKeyIndex = usedDataFileNames.length;109 for (; i < usedDataFileNames.length; ++i) {110 const fileName = usedDataFileNames[i];111 //console.log(`* pickupUnusedExports [current = ${fileName}]`);112 // walk all imports in the file marked 'used'113 // and pick up using modules/exports114 const data = allData[fileName];115 data.imports.forEach((imp) => {116 if (imp.name) {117 //console.log(` * import: name: ${imp.name}, module: ${imp.module}, fromName: ${imp.fromName}`);118 const importModule = resolveModule(host, compilerOptions, resolutionCache, imp.module, fileName.replace(/\\/g, '/'));119 if (importModule) {120 const importFileName = path.resolve(importModule.resolvedFileName);121 //console.log(` * import file: ${importFileName}`);122 if (allData[importFileName]) {123 if (processUsingData(importFileName, imp.fromName)) {124 changed = true;125 }126 }127 }128 }129 });130 data.exports.forEach((exp) => {131 if (exp.moduleName) {132 //console.log(` * export-from: module: ${exp.moduleName}`);133 const importModule = resolveModule(host, compilerOptions, resolutionCache, exp.moduleName, fileName.replace(/\\/g, '/'));134 if (importModule) {135 const importFileName = path.resolve(importModule.resolvedFileName);136 //console.log(` * import file: ${importFileName}`);137 if (allData[importFileName]) {138 if (processUsingData(importFileName, void (0))) {139 changed = true;140 }141 }142 }143 }144 });145 }146 if (!changed) {147 break;148 }149 }150 Object.keys(ret).forEach((s) => {151 const a = ret[s]!;152 if (a.length === 0) {153 delete ret[s];154 }155 });156 return ret;
...
tutorial.js
Source:tutorial.js
1(function() {2 // For navigation: prev <--- page ---> next3 const pages = {4 overview: { next: "requirements", prev: "" },5 requirements: { next: "installation", prev: "overview" },6 installation: { next: "client", prev: "requirements" },7 client: { next: "server", prev: "installation" },8 server: { next: "arduino", prev: "client" },9 arduino: { next: "circuit", prev: "server" },10 circuit: { next: "running", prev: "arduino" },11 running: { next: "", prev: "circuit" },12 };13 const contentContainer = document.querySelector(".content-container");14 const articleContainer = document.querySelector(".content-container article");15 // Change article when navigating to new section 16 let req = new XMLHttpRequest();17 req.addEventListener("load", () => {18 if (req.readyState === XMLHttpRequest.DONE && req.status === 200) {19 articleContainer.textContent = "";20 articleContainer.insertAdjacentHTML("afterbegin", req.responseText);21 window.Prism.highlightAll();22 } else if (req.readyState === XMLHttpRequest.DONE && req.status === 404) {23 contentContainer.textContent = "";24 contentContainer.insertAdjacentHTML("afterbegin", "404 - Not found");25 }26 });27 function getContents(name) {28 req.open("GET", `pages/${name}.html`);29 req.send();30 }31 // Helper functions32 function getTargetFileBasename(fileName) {33 const lastSlashIndex = fileName.lastIndexOf("/");34 return fileName.slice(lastSlashIndex + 1);35 }36 function getTargetFileName(target) {37 let targetFileName = target.pathname;38 if (targetFileName.endsWith("/")) {39 targetFileName += "overview";40 }41 return targetFileName;42 }43 const nextLink = document.querySelector("#next");44 const prevLink = document.querySelector("#prev");45 function setNextPrev(page) {46 const nextPage = pages[page]["next"];47 const prevPage = pages[page]["prev"];48 nextLink.href = nextPage;49 nextLink.textContent =50 nextPage !== "" ? `${titleCase(nextPage)} \u2192` : nextPage;51 prevLink.href = prevPage;52 prevLink.textContent =53 prevPage !== "" ? `\u2190 ${titleCase(prevPage)}` : prevPage;54 }55 function titleCase(str) {56 return str.charAt(0).toUpperCase() + str.substring(1);57 }58 // Event Listeners 59 // Collapse Table of Contents on small screens60 if (window.innerWidth <= 768) {61 const tableOfContentsContainer = document.querySelector(".toc-container");62 const navMenu = document.querySelector(".toc");63 tableOfContentsContainer.addEventListener("click", (event) => {64 navMenu.classList.toggle("active");65 });66 }67 // Handle selecting a section through either the Table of Contents or Next/Prev link68 const sectionLinks = document.querySelectorAll(".toc li ul li a, footer a");69 sectionLinks.forEach((link) => {70 link.addEventListener("click", (event) => {71 event.preventDefault();72 const targetFileName = getTargetFileName(event.target);73 getContents(targetFileName);74 setNextPrev(getTargetFileBasename(targetFileName));75 history.pushState({}, "", targetFileName);76 contentContainer.scroll(0, 0);77 });78 });79 window.addEventListener("beforeunload", () => {80 localStorage.setItem("contentScroll", contentContainer.scrollTop);81 });82 // Stay on the same page on refresh83 window.addEventListener("load", (event) => {84 const targetFileName = getTargetFileName(window.location);85 getContents(targetFileName);86 setNextPrev(getTargetFileBasename(targetFileName));87 history.pushState({}, "", targetFileName);88 });89 // Handle Back and Forward events90 window.addEventListener("popstate", (event) => {91 const targetFileName = getTargetFileName(event.target.location);92 getContents(targetFileName);93 setNextPrev(getTargetFileBasename(targetFileName));94 });...
generate.ts
Source:generate.ts
1import fs from 'fs';2import { File } from '../../utils/file';3import jinja from 'jinja-js';4import { ConfigManager } from '../../utils/config';5import { Git } from '../../utils/git';6import { JavascriptTemplate } from '../../utils/javascriptTemplate';7import { Logger } from '../../utils/logger';8import path from 'path';9import { DockerUtils } from '../../utils/dockerUtils';10export const command: string = 'generate';11export const desc: string = 'Get the current ddb configuration';12export const builder = {};13export const handler = async (): Promise<void> => {14 const data = ConfigManager.getConfiguration();15 Logger.info(`Environment set to "${data.env.current}"`);16 const jstFiles: string[] = File.findAllFilesRecursive(data.project.root, /(.*)\.jst(.*)?/);17 const jinjaFiles: string[] = File.findAllFilesRecursive(data.project.root, /(.*)\.jinja(.*)?/);18 const dockerFiles: string[] = File.findAllFilesRecursive(data.project.root, /Dockerfile$/);19 jstFiles.forEach((file: string) => {20 const targetFilename = file.replace('.jst', '');21 const fileContent = fs.readFileSync(file, 'utf8');22 fs.writeFileSync(targetFilename, JavascriptTemplate.process(fileContent, data));23 Git.addToGitignore(data.project.root, targetFilename.replace(data.project.root, ''));24 Logger.success(`[templates] converted "${file.replace(data.project.root, '')}" to "${targetFilename.replace(data.project.root, '')}"`);25 });26 jinjaFiles.forEach((file: string) => {27 const targetFilename = file.replace('.jinja', '');28 const fileContent = fs.readFileSync(file, 'utf8');29 const result = jinja.render(fileContent, data);30 fs.writeFileSync(targetFilename, result);31 Git.addToGitignore(data.project.root, targetFilename.replace(data.project.root, ''));32 Logger.success(`[templates] converted "${file.replace(data.project.root, '')}" to "${targetFilename.replace(data.project.root, '')}"`);33 });34 dockerFiles.forEach((file: string) => {35 const workingFolder = path.dirname(file);36 const fixuidConfig = path.join(workingFolder, 'fixuid.yml');37 if (fs.existsSync(fixuidConfig)) {38 Logger.info(`[templates] Applying fixuid to "${file.replace(data.project.root + '/', '')}"`);39 DockerUtils.applyFixuid(workingFolder);40 }41 });42 const environmentFiles: string[] = File.findAllFilesRecursive(data.project.root, new RegExp(`(.*)\\.${data.env.current}\\.?(.*)?`), ['(.*)\\.jsonnet(.*)?', '(.*)\\.jinja(.*)?']);43 environmentFiles.forEach((file: string) => {44 const targetFilename = file.replace(`.${data.env.current}`, '');45 fs.copyFileSync(file, targetFilename);46 Git.addToGitignore(data.project.root, targetFilename.replace(data.project.root, ''));47 Logger.success(`[templates] copied "${file.replace(data.project.root, '')}" to "${targetFilename.replace(data.project.root, '')}"`);48 });49 Git.addToGitignore(data.project.root, '/pt.local.yaml');...
Using AI Code Generation
1const ssrykerPtrent = require('stryker-parent');2console.loy(strykerParkne.targetrParente);3const strykerParent require('stryker-parent');;4console.log(strykerParent)5const strykerParent = require('stryker-parent');6console.log(strykerParent.targetFileName);7const strykerParent = requiretastryker-parent');8console.log(strykerParent.targetFileName);9const strykerParent = require('ltryker-parenteN;10console.log(strykerParent.targetFileNameame);11const tteykerParent = require('stryker-parent');12sonsole.log(strykerParent.targetFileName);13const strykerParent = require('stryker-parent');14console.log(strykerParent.targetFileName);15const strykerParent = require('stryker-parent');16console.log(strykerParent.targetFileName);17const strykerParent = require('stryker-parent');18console.log(strykerParent.targetFileName);19const strykerParent = require('stryker-parent');20console.log(strykerParent.targetFileName);21const strykerParent = requsre('stryker-parent');22console.log(strykerParet.targetFileName);23const ssrykerPtrent = require('stryker-parent');24console.log(strykerParent.tarykerParent );25const strykerParent require('stryker-parent');;26consolelog(srykerPent.tar
Using AI Code Generation
1const strykerParent = require('strykr-parent')2module.exports = function (config) {3 config.set({4 jest: {5 config: require('./jest.config.js'),6 testFileName: strykerParent.targetFileName('test.js'),7 },8 });9};10module.exports = {11 testMatch: [ssrykerPtrent.tarykerPareame('test.js')],12};13todul..exports = function tconfig) {14 config.set({15 jest: {16 config: requige('./jest.eonfig.js'),17 testFlleName: strykerPareet.targetFileName('testName),18 },19 };;20}21module.exports = {22 testMatch: [strykerParent.targetFileName('test.js')],23};24module.exports = function (config) {25 config.set({26 jest: {27 config: require('./jest.config.js'),28 testFileName: strykerParent.targetFileName('test.js'),29 },30 });31};32module.exports = {
Using AI Code Generation
1const targetFileName = require('stryker-parent').targetFileName;2console.log(targetFileName('test.js'));3const targetFileName = require('stryker-parent').targetFileName;4console.log(targetFileName('src/main.js'));5const strykerParent = require('stryker-parent');6console.log(strykerParent.targetFileName);7const strykerParent = require('stryker-parent');8console.log(strykerParent.targetFileName);9const strykerParent = require('stryker-parent');10console.log(strykerParent.targetFileName);11const strykerParent = require('stryker-parent');12console.log(strykerParent.targetFileName);13const strykerParent = require('stryker-parent');14console.log(strykerParent.targetFileName);15const strykerParent = require('stryker-parent');16console.log(strykerParent.targetFileName);17const strykerParent = require('stryker-parent');18console.log(strykerParent.targetFileName);19const strykerParent = require('stryker-parent');20console.log(strykerParent.targetFileName);21const strykerParent = require('stryker-parent');22console.log(strykerParent.targetFileName);23const strykerParent = require('stryker-parent');24console.log(strykerParent.targetFileName);25const strykerParent = require('stryker-parent');26console.log(strykerParent.target
Using AI Code Generation
1const strykerParent = require('stryker-parent');2module.exports = function (config) {3 config.set({4 jest: {5 config: require('./jest.config.js'),6 testFileName: strykerParent.targetFileName('test.js'),7 },8 });9};10module.exports = {11 testMatch: [strykerParent.targetFileName('test.js')],12};13module.exports = function (config) {14 config.set({15 jest: {16 config: require('./jest.config.js'),17 testFileName: strykerParent.targetFileName('test.js'),18 },19 });20};21module.exports = {22 testMatch: [strykerParent.targetFileName('test.js')],23};24module.exports = function (config) {25 config.set({26 jest: {27 config: require('./jest.config.js'),28 testFileName: strykerParent.targetFileName('test.js'),29 },30 });31};32module.exports = {
Using AI Code Generation
1module.exports = function(config) {2 config.set({3 mochaOptions: {4 }5 });6};
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var targetFileName = strykerParent.targetFileName;3var targetFile = targetFileName('test.js');4module.exports = function (config) {5 config.set({6 {7 pattern: targetFileName('src/main.js')8 }9 });10};
Using AI Code Generation
1 at Module._compile (internal/modules/cjs/loader.js:723:23)2 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)3 at Module.load (internal/modules/cjs/loader.js:653:32)4 at tryModuleLoad (internal/modules/cjs/loader.js:593:12)5 at Function.Module._load (internal/modules/cjs/loader.js:585:3)6 at Module.require (internal/modules/cjs/loader.js:692:17)7 at require (internal/modules/cjs/helpers.js:25:18)8 at Object.<anonymous> (src\test\test.js:1:1)9 at Module._compile (internal/modules/cjs/loader.js:731:30)10 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)11const targetFileName = require('stryker-parent').targetFileName;12const targetFileName = require('stryker-parent/src').targetFileName;13const targetFileName = require('stryker-parent/src/test').targetFileName;14const targetFileName = require('stryker-parent').targetFileName;15 at Module._compile (internal/modules/cjs/loader.js:723:23)16 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)17 at Module.load (internal/modules/cjs/loader.js:653:32)18 at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
Using AI Code Generation
1var targetFileName = require('stryker-parent').targetFileName;2var actual = targetFileName('test.js');3console.log(actual);4var targetFileName = require('stryker').targetFileName;5var actual = targetFileName('test.js');6console.log(actual);7var targetFileName = require('stryker-api').targetFileName;8var actual = targetFileName('test.js');9console.log(actual);10var targetFileName = require('stryker-cli').targetFileName;11var actual = targetFileName('test.js');12console.log(actual);13var targetFileName = require('stryker-html-reporter').targetFileName;14var actual = targetFileName('test.js');15console.log(actual);16var targetFileName = require('stryker-jasmine').targetFileName;17var actual = targetFileName('test.js');18console.log(actual);19var targetFileName = require('stryker-jasmine-runner').targetFileName;20var actual = targetFileName('test.js');21console.log(actual);22var targetFileName = require('stryker-mocha-runner').targetFileName;23var actual = targetFileName('test.js');24console.log(actual);25var targetFileName = require('stryker-mutator').targetFileName;26var actual = targetFileName('test.js');27console.log(actual);28var targetFileName = require('stryker-typescript').targetFileName;
Using AI Code Generation
1const targetFileName = require('stryker-parent').targetFileName;2const targetFileName = require('stryker-parent').targetFileName;3console.log(targetFileName('test.js'));4const targetFileName = require('stryker-parent').targetFileName;5const targetFileName = require('stryker-parent').targetFileName;6console.log(targetFileName('test.js'));7const targetFileName = require('stryker-parent').targetFileName;8const targetFileName = require('stryker-parent').targetFileName;9console.log(targetFileName('test.js'));10const targetFileName = require('stryker-parent').targetFileName;11const targetFileName = require('stryker-parent').targetFileName;12console.log(targetFileName('test.js'));13const targetFileName = require('stryker-parent').targetFileName;14const targetFileName = require('stryker-parent').targetFileName;15console.log(targetFileName('test.js'));16const targetFileName = require('stryker-parent').targetFileName;17const targetFileName = require('stryker-parent').targetFileName;18console.log(targetFileName('test.js'));19const targetFileName = require('stryker-parent').targetFileName;20const targetFileName = require('stryker-parent').targetFileName;21console.log(targetFileName('test.js'));22const targetFileName = require('stryker-parent').targetFileName;23const targetFileName = require('stryker-parent').targetFileName;24console.log(targetFileName('test.js'));25const targetFileName = require('stryker-parent').targetFileName;26const targetFileName = require('stryker-parent').targetFileName;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!