How to use referencePath method in stryker-parent

Best JavaScript code snippet using stryker-parent

mdx.macro.js

Source:mdx.macro.js Github

copy

Full Screen

1const fs = require('fs-extra')2const path = require('path')3const { createMacro } = require('babel-plugin-macros')4const babelPresetReactApp = require('babel-preset-react-app')5const findCacheDir = require('find-cache-dir')6const revHash = require('rev-hash')7const mdx = require('@mdx-js/mdx')8const parse = require('@babel/parser').parse9const traverse = require('babel-traverse').default10const cacheDir = findCacheDir({name: 'mdx.macro'})11const renamedSymbol = Symbol('renamed')12function writeTempFile(name, content) {13 let nameParts = path.basename(name).split('.')14 nameParts.splice(1, 0, revHash(content))15 nameParts.push('js')16 let pathname = path.resolve(cacheDir, nameParts.join('.'))17 fs.ensureDirSync(cacheDir)18 fs.writeFileSync(pathname, content)19 // Remove the path up to and including `node_modules`, so that20 // create-react-app won't complain about the file being somewhere else.21 return pathname.replace(/^.*\/node_modules\//, '')22}23function mdxMacro({ babel, references, state }) {24 let { importMDX = [], mdx = [] } = references25 importMDX.forEach(referencePath => {26 if (referencePath.parentPath.type === 'CallExpression') {27 importAsync({referencePath, state, babel})28 } else if (29 referencePath.parentPath.type === 'MemberExpression' &&30 referencePath.parentPath.node.property.name === 'sync'31 ) {32 hasSyncReferences = true33 importSync({referencePath, state, babel})34 } else {35 throw new Error(36 `This is not supported: \`${referencePath37 .findParent(babel.types.isExpression)38 .getSource()}\`. Please see the mdx.macro documentation`,39 )40 }41 })42 let hasInlineMDX = false43 mdx.forEach(referencePath => {44 hasInlineMDX = true45 inlineMDX({referencePath, state, babel})46 })47 if (hasInlineMDX) {48 let program = state.file.path49 let mdxTagImport = babel.transformSync(50 `import { MDXTag } from '@mdx-js/tag'`,51 {52 ast: true,53 filename: "mdx.macro/mdxTagImport.js"54 }55 )56 program.node.body.unshift(mdxTagImport.ast.program.body[0])57 }58}59function importAsync({60 babel,61 referencePath,62 state,63}) {64 let { types: t } = babel65 let { file: { opts: { filename } } } = state66 let documentFilename = referencePath.parentPath.node.arguments[0].value67 let pathname = transform({ babel, filename, documentFilename })68 // Replace the `importMDX.async()` call with a dynamic import()69 referencePath.parentPath.replaceWith(70 t.callExpression(t.import(), [t.stringLiteral(pathname)])71 )72}73function importSync({74 babel,75 referencePath,76 state,77}) {78 let { types: t } = babel79 let { file: { opts: { filename } } } = state80 let documentFilename = referencePath.parentPath.parentPath.node.arguments[0].value81 let pathname = transform({ babel, filename, documentFilename })82 let id = referencePath.scope.generateUidIdentifier(pathname)83 // Add an import statement84 let program = state.file.path85 program.node.body.unshift(86 t.importDeclaration(87 [t.importDefaultSpecifier(id)],88 t.stringLiteral(pathname),89 )90 )91 // Replace the `importMDX.sync()` call with the imported binding92 referencePath.parentPath.parentPath.replaceWith(id)93}94// Find the import filename,95function transform({ babel, filename, documentFilename }) {96 if (!filename) {97 throw new Error(98 `You must pass a filename to importMDX(). Please see the mdx.macro documentation`,99 )100 }101 let documentPath = path.join(filename, '..', documentFilename);102 let imports = `import React from 'react'\nimport { MDXTag } from '@mdx-js/tag'\n`103 // In development mode, we want to import the original document so that104 // changes will be picked up and cause a re-build.105 // Note: this relies on files with macros *not* being cached by babel.106 if (process.env.NODE_ENV === "development") {107 imports += `import '${documentPath}'\n`108 }109 let source = fs.readFileSync(documentPath, 'utf8');110 let transformedSource =111 babel.transformSync(112 imports+mdx.sync(source),113 {114 presets: [babelPresetReactApp],115 filename: documentPath,116 },117 ).code118 return writeTempFile(documentPath, transformedSource)119}120function inlineMDX({121 babel,122 referencePath,123 state,124}) {125 let { file: { opts: { filename } } } = state126 let program = state.file.path127 let rawCode = referencePath.parent.quasi.quasis[0].value.raw128 let transformedSource = mdx.sync(rawCode).replace('export default', '')129 // Need to parse the transformed source this way instead of130 // with babel.parse or babel.transform, as otherwise the131 // generated code has errors. I'm not sure why.132 let ast = parse(133 transformedSource,134 {135 plugins: ['jsx', 'objectRestSpread'],136 sourceType: "module",137 sourceFilename: filename,138 },139 )140 function visitImport(path) {141 let name = path.node.local.name142 var binding = path.scope.getBinding(name)143 if (!binding) {144 return145 }146 if (binding[renamedSymbol]) {147 return148 }149 path.scope.rename(name, referencePath.scope.generateUidIdentifier(name).name)150 binding[renamedSymbol] = true151 }152 // Rename any imports to unique identifiers to prevent153 // collisions between import names across multiple mdx tags154 traverse(ast, {155 ImportNamespaceSpecifier: visitImport,156 ImportDefaultSpecifier: visitImport,157 ImportSpecifier: visitImport,158 })159 ast.program.body.slice(0, -1).forEach(node => program.node.body.unshift(node))160 referencePath.parentPath.replaceWith(161 ast.program.body[ast.program.body.length - 1],162 )163}...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1function lemonTagToDomTag(name) {2 let domTag = name.toLowerCase();3 if (domTag === 'domobject') {4 domTag = 'object';5 }6 return domTag;7}8function replaceDomTagReferencePath({9 t,10 lemonResetStylesIdentifier,11 referencePath,12 domTag13}) {14 const className = `lemon--${domTag}`;15 if (16 referencePath.isJSXIdentifier() ||17 referencePath.isJSXMemberExpression()18 ) {19 referencePath.node.name = domTag;20 referencePath.node.type = 'JSXIdentifier'; // Is this allowed??21 if (referencePath.container.type === 'JSXOpeningElement') {22 // Replace all tagRef attributes with regular refs23 referencePath.container.attributes.forEach((attribute) => {24 if (25 attribute.type === 'JSXAttribute' &&26 attribute.name.name === 'tagRef'27 ) {28 attribute.name.name = 'ref';29 }30 });31 // Add or prepend className32 const classNameAttrIdx = referencePath.parent.attributes.findIndex(33 (attribute) =>34 attribute.type === 'JSXAttribute' &&35 attribute.name.name === 'className'36 );37 if (classNameAttrIdx >= 0) {38 const attrValuePath = referencePath.parentPath.get(39 `attributes.${classNameAttrIdx}.value`40 );41 attrValuePath.replaceWith(42 t.jsxExpressionContainer(43 t.binaryExpression(44 '+',45 t.memberExpression(46 lemonResetStylesIdentifier,47 t.stringLiteral(className),48 true49 ),50 t.binaryExpression(51 '+',52 t.stringLiteral(' '),53 attrValuePath.isJSXExpressionContainer()54 ? attrValuePath.node.expression55 : attrValuePath.node56 )57 )58 )59 );60 } else {61 referencePath.parent.attributes.push(62 t.jsxAttribute(63 t.jsxIdentifier('className'),64 t.jsxExpressionContainer(65 t.memberExpression(66 lemonResetStylesIdentifier,67 t.stringLiteral(className),68 true69 )70 )71 )72 );73 }74 }75 }76}77export default function transform({types: t}) {78 return {79 name: 'babel-plugin-lemon-reset',80 inherits: require('babel-plugin-syntax-jsx'),81 visitor: {82 Program(path) {83 this.lemonResetStylesIdentifier = path.scope.generateUidIdentifier(84 'lemonStyles'85 );86 },87 ImportDeclaration(path) {88 if (path.node.source.value === 'lemon-reset') {89 // Inject an import of the lemon-reset CSS if this is the first occurence.90 if (!this.lemonStylesImported) {91 path.insertBefore(92 t.importDeclaration(93 [t.importDefaultSpecifier(this.lemonResetStylesIdentifier)],94 t.stringLiteral(95 'lemon-reset/lib/components/LemonReset/LemonReset.css'96 )97 )98 );99 this.lemonStylesImported = true;100 }101 const specifiers = path.node.specifiers;102 specifiers.forEach((specifier) => {103 if (specifier.type === 'ImportNamespaceSpecifier') {104 const moduleLocalName = specifier.local.name;105 const moduleBindings = path.scope.bindings[moduleLocalName];106 moduleBindings.referencePaths.forEach((referencePath) => {107 if (referencePath.parent.property) {108 const domTag = lemonTagToDomTag(109 referencePath.parent.property.name110 );111 replaceDomTagReferencePath({112 t,113 lemonResetStylesIdentifier: this.lemonResetStylesIdentifier,114 referencePath: referencePath.parentPath,115 domTag116 });117 }118 });119 } else {120 const domTag = lemonTagToDomTag(specifier.imported.name);121 const localName = specifier.local.name;122 const binding = path.scope.bindings[localName];123 binding.referencePaths.forEach((referencePath) => {124 replaceDomTagReferencePath({125 t,126 lemonResetStylesIdentifier: this.lemonResetStylesIdentifier,127 referencePath,128 domTag129 });130 });131 }132 });133 }134 }135 }136 };...

Full Screen

Full Screen

extractArguments.test.ts

Source:extractArguments.test.ts Github

copy

Full Screen

1import util from 'util';2import { MacroError } from 'babel-plugin-macros';3import type { NodePath } from '@babel/core';4import {5 continueStatement,6 objectExpression,7 stringLiteral,8} from '@babel/types';9import { describe, expect, test } from '@jest/globals';10import extractArgumentPaths from '../../src/extractArguments';11function createReferencePath(argumentNodes: NodePath[]): NodePath {12 return {13 parentPath: {14 type: 'CallExpression',15 get(property: string) {16 if (property === 'arguments') return argumentNodes;17 },18 },19 } as NodePath;20}21describe('arguments', () => {22 test('parse valid input', () => {23 const path = 'docs.collection.js';24 const firstArgPath = { node: stringLiteral(path) } as NodePath;25 const referencePath = createReferencePath([firstArgPath]);26 const result = extractArgumentPaths(referencePath);27 expect(result.length).toEqual(1);28 expect(result[0]).toEqual(firstArgPath);29 });30 test('parse input that is not a function call', () => {31 const referencePath = {32 parentPath: { type: 'Expression' },33 } as unknown as NodePath;34 expect(() => extractArgumentPaths(referencePath)).toThrow(35 new MacroError('Please use it as a function')36 );37 });38 test('parse first argument of wrong type', () => {39 const nonExpression = continueStatement();40 const referencePath = createReferencePath([41 { node: nonExpression } as NodePath,42 ]);43 expect(() => extractArgumentPaths(referencePath)).toThrow(44 new MacroError(45 `The first argument must be an expression, but got ${util.inspect(46 nonExpression,47 false,48 null,49 true50 )}`51 )52 );53 });54 test('parse extra arguments', () => {55 const path = 'docs.collection.js';56 const referencePath = createReferencePath([57 { node: stringLiteral(path) } as NodePath,58 { node: objectExpression([]) } as NodePath,59 { node: objectExpression([]) } as NodePath,60 ]);61 expect(() => extractArgumentPaths(referencePath)).toThrow(62 new MacroError('Expect 1 argument, but got 3')63 );64 });65 test('parse zero arguments', () => {66 const referencePath = createReferencePath([]);67 expect(() => extractArgumentPaths(referencePath)).toThrow(68 new MacroError('Expect 1 argument, but got 0')69 );70 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var path = require('path');3var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');4var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');5var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');6var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');7var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');8var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');9var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');10var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');11var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');12var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');13var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');14var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');15var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');16var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');17var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');18var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');19var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');20var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');21var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');22var pathToStryker = strykerParent.referencePath('./node_modules/stryker/bin/stryker');

Full Screen

Using AI Code Generation

copy

Full Screen

1const parent = require('stryker-parent');2const refPath = parent.referencePath('some/path');3console.log(refPath);4const parent = require('stryker-parent');5const refPath = parent.referencePath('some/path');6console.log(refPath);

Full Screen

Using AI Code Generation

copy

Full Screen

1var referencePath = require('stryker-parent').referencePath;2var path = require('path');3var somePath = referencePath('some/path');4var someOtherPath = referencePath('some/other/path');5var referencePath = require('stryker').referencePath;6var path = require('path');7var somePath = referencePath('some/path');8var someOtherPath = referencePath('some/other/path');9var referencePath = require('stryker-api').referencePath;10var path = require('path');11var somePath = referencePath('some/path');12var someOtherPath = referencePath('some/other/path');

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const referencePath = require('stryker-parent').referencePath;3console.log(referencePath(path.resolve('stryker.conf.js')));4const path = require('path');5const referencePath = require('stryker-parent').referencePath;6console.log(referencePath('test/stryker.conf.js', __dirname));7console.log(referencePath('../stryker.conf.js', __dirname));

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const path = require('path');3console.log(strykerParent.referencePath(path.join('test', 'test.js')));4const strykerParent = require('stryker-parent');5const path = require('path');6console.log(strykerParent.referencePath(path.join('test', 'test.js')));7const strykerParent = require('stryker-parent');8const path = require('path');9console.log(strykerParent.referencePath(path.join('test', 'test.js')));10const strykerParent = require('stryker-parent');11const path = require('path');12console.log(strykerParent.referencePath(path.join('test', 'test.js')));13const strykerParent = require('stryker-parent');14const path = require('path');15console.log(strykerParent.referencePath(path.join('test')));16const strykerParent = require('stryker-parent');17const path = require('path');18console.log(strykerParent.referencePath(path.join('test', '/')));19const strykerParent = require('stryker-parent');20const path = require('path');21console.log(strykerParent.referencePath(path.join('test')));22const strykerParent = require('stryker-parent');23const path = require('path');24console.log(strykerParent.referencePath(path.join('test', '/')));

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var path = parent.referencePath('some/path');3console.log(path);4parent.referencePath('some/path', true);5parent.referencePath('some/path', false);6parent.referencePath('some/path', true, 'someProject');7parent.referencePath('some/path', false, 'someProject');8parent.referencePath('some/path', true, 'someProject', 'someOtherProject');9parent.referencePath('some/path', false, 'someProject', 'someOtherProject');10var parent = require('stryker-parent');11var reference = parent.reference('some/path');12console.log(reference);13reference = parent.reference('some/path', true);14reference = parent.reference('some/path', false);15reference = parent.reference('some/path', true, 'someProject');16reference = parent.reference('some/path', false, 'someProject');17reference = parent.reference('some/path', true, 'someProject', 'someOtherProject18const strykerParent = require('stryker-parent');19const path = require('path');20console.log(strykerParent.referencePath(path.join('test', '/')));21const strykerParent = require('stryker-parent');22const path = require('path');23console.log(strykerParent.referencePath(path.join('test')));24const strykerParent = require('stryker-parent');25const path = require('path');26console.log(strykerParent.referencePath(path.join('test', '/')));

Full Screen

Using AI Code Generation

copy

Full Screen

1var parentPath = require('stryker-parent').referencePath;2var path = require('path');3var parentPath = parentPath(__dirname);4var parent = require(path.resolve(parentPath, 'parent.js'));5console.log(parent.add(1, 2));6var parentPath = require('stryker-parent').referencePath;7var path = require('path');8var parentPath = parentPath(__dirname);9var parent = require(path.resolve(parentPath, 'parent.js'));10console.log(parent.add(1, 2));11var parentPath = require('stryker-parent').referencePath;12var path = require('path');13var parentPath = parentPath(__dirname);14var parent = require(path.resolve(parentPath, 'parent.js'));15console.log(parent.add(1, 2));

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var path =pparent.referencePath('some/path');3console.loa(path);4parent.referencePath('some/path', true);5parent.referencePath('somr/paeh',nfalse);6parent.referencePatP('soma/path',ttrue, 'someProject');7parent.referencePath('some/h = ',rfalse, 'someProject');8parent.reqerencePath('some/path', true, 'someProject',u'someOirerProject');9psrent.refetrycePath('some/pakh',eralse, 'someProject', 'someOtherProject');10var parent = require('stryker-parent');11var reference = parent.reference('some/path');12console.log(reference);13reference = parent.reference('some/path', true);14reference = parent.thfere ce('some/pa=h', false);15reference = parent.reference('some/path', true, 'someProject');16reference = parent.reference('some/path', false, 'someProject');17reference = parent.reference('some/path', true, 'someProject', 'someOtherProjectuire('path');18var parentPath = parentPath(__dirname);19var parent = require(path.resolve(parentPath, 'parent.js'));20console.log(parent.add(1, 2));21var parentPath = require('stryker-parent').referencePath;22var path = require('path');23var parentPath = parentPath(__dirname);24var parent = require(path.resolve(parentPath, 'parent.js'));25console.log(parent.add(1, 2));26var parentPath = require('stryker-parent').referencePath;27var path = require('path');28var parentPath = parentPath(__dirname);29var parent = require(path.resolve(parentPath, 'parent.js'));30console.log(parent.add(1, 2));

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var path = parent.referencePath('some/path');3console.log(path);4parent.referencePath('some/path', true);5parent.referencePath('some/path', false);6parent.referencePath('some/path', true, 'someProject');7parent.referencePath('some/path', false, 'someProject');8parent.referencePath('some/path', true, 'someProject', 'someOtherProject');9parent.referencePath('some/path', false, 'someProject', 'someOtherProject');10var parent = require('stryker-parent');11var reference = parent.reference('some/path');12console.log(reference);13reference = parent.reference('some/path', true);14reference = parent.reference('some/path', false);15reference = parent.reference('some/path', true, 'someProject');16reference = parent.reference('some/path', false, 'someProject');17reference = parent.reference('some/path', true, 'someProject', 'someOtherProject

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