MCPcopy Create free account
hub / github.com/npm/cli / createTestdir

Function createTestdir

workspaces/libnpmexec/test/fixtures/setup.js:94–119  ·  view source on GitHub ↗
(...objs)

Source from the content-addressed store, hash-verified

92}
93
94const createTestdir = (...objs) => {
95 const testdirHelper = (obj, ancestors = []) => {
96 for (const [key, value] of Object.entries(obj)) {
97 if (extname(key) === '.json') {
98 obj[key] = JSON.stringify(value, null, 2)
99 } else if (extname(key) === '.js' || ancestors.slice(-2).join('/') === 'node_modules/.bin') {
100 // a js or bin file is converted to a bin script that writes a file
101 obj[key] = `#!/usr/bin/env node\nrequire('fs').writeFileSync(
102 'output-${value.key.replace('/', '-')}',
103 JSON.stringify({
104 value: '${value.value}',
105 args: process.argv.slice(2),
106 created: '${[...ancestors, key].join('/')}',
107 })
108 )`
109 } else if (value && typeof value === 'object') {
110 obj[key] = testdirHelper(value, [...ancestors, key])
111 } else {
112 obj[key] = value
113 }
114 }
115 return obj
116 }
117
118 return testdirHelper(merge(...objs))
119}
120
121const setup = (t, {
122 pkg,

Callers 1

setupFunction · 0.85

Calls 2

mergeFunction · 0.85
testdirHelperFunction · 0.70

Tested by

no test coverage detected