-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make test paths Windows safe #87
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,35 @@ import 'babel-polyfill'; | |
|
||
import assert from 'assert'; | ||
import { exec } from 'mz/child_process'; | ||
import { exists, readFile, writeFile } from 'mz/fs'; | ||
import { exists, readFile, writeFile, mkdtemp, mkdir } from 'mz/fs'; | ||
import { join, sep, normalize } from 'path'; | ||
|
||
|
||
import getFilesUnderPath from '../src/util/getFilesUnderPath'; | ||
|
||
let originalCwd = process.cwd(); | ||
|
||
async function mkdTempSafe (prefix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment explaining what |
||
let parts = normalize(prefix).split(sep); | ||
// let last = parts.pop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you left this line in by mistake? |
||
let head = ''; | ||
for (let part of parts) { | ||
try { | ||
head = join(head, part); | ||
await mkdir(head); | ||
} catch (e) { | ||
if (e.code === 'EEXIST') continue; | ||
throw e; | ||
} | ||
} | ||
return await mkdtemp(prefix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I hadn't seen |
||
} | ||
|
||
async function runCli(args) { | ||
let [stdout, stderr] = (await exec(`"${originalCwd}/bin/bulk-decaffeinate" \ | ||
--decaffeinate-path "${originalCwd}/node_modules/.bin/decaffeinate" \ | ||
--jscodeshift-path "${originalCwd}/node_modules/.bin/jscodeshift" \ | ||
--eslint-path "${originalCwd}/node_modules/.bin/eslint" \ | ||
let [stdout, stderr] = (await exec(`node "${join(originalCwd,'bin','bulk-decaffeinate')}" \ | ||
--decaffeinate-path "${join(originalCwd, 'node_modules', '.bin', 'decaffeinate')}" \ | ||
--jscodeshift-path "${join(originalCwd, 'node_modules', '.bin', 'jscodeshift')}" \ | ||
--eslint-path "${join(originalCwd, 'node_modules', '.bin', 'eslint')}" \ | ||
${args}`)); | ||
return {stdout, stderr}; | ||
} | ||
|
@@ -52,10 +70,10 @@ async function assertFilesEqual(actualFile, expectedFile) { | |
* given example. | ||
*/ | ||
async function runWithTemplateDir(exampleName, fn) { | ||
let suffix = Math.floor(Math.random() * 1000000000000); | ||
let newDir = `./test/tmp-projects/${exampleName}-${suffix}`; | ||
let newDirPref = `./test/tmp-projects/${exampleName}/tmp-`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the whole word "prefix" instead of "pref"? In my mind, "pref" means "preference". Also, looks like you added an extra level of nesting here, which is causing the test failure. I'd rather just keep the same nesting level as before (which also make makes it easier to potentially avoid |
||
let newDir; | ||
try { | ||
await exec(`mkdir -p "${newDir}"`); | ||
newDir = await mkdTempSafe(newDirPref); | ||
await exec(`cp -r "./test/examples/${exampleName}/." "${newDir}"`); | ||
process.chdir(newDir); | ||
await fn(); | ||
|
@@ -109,19 +127,19 @@ describe('simple-error', () => { | |
|
||
await assertFileIncludes( | ||
'decaffeinate-errors.log', | ||
'===== test/examples/simple-error/error.coffee' | ||
`===== ${join('test','examples','simple-error','error.coffee')}` | ||
); | ||
|
||
let results = JSON.parse((await readFile('decaffeinate-results.json')).toString()); | ||
assert.equal(results.length, 2); | ||
assert.equal(results[0].path, 'test/examples/simple-error/error.coffee'); | ||
assert.equal(results[0].path, join('test', 'examples', 'simple-error', 'error.coffee')); | ||
assert.notEqual(results[0].error, null); | ||
assert.equal(results[1].path, 'test/examples/simple-error/success.coffee'); | ||
assert.equal(results[1].path, join('test', 'examples', 'simple-error', 'success.coffee')); | ||
assert.equal(results[1].error, null); | ||
|
||
await assertFileContents( | ||
'decaffeinate-successful-files.txt', | ||
'test/examples/simple-error/success.coffee' | ||
`${join('test', 'examples', 'simple-error', 'success.coffee')}` | ||
); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, looks like mkdtemp was introduced in node 5, and I'd like to support node 4, so probably best to stick with the old random number approach unless there's a problem with it.