-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Change the current working directory of tests to be the same directory as package.json #1074
Changes from all commits
c97a404
844821f
033ff7b
d4ca886
efd095b
48831d1
aa80383
20a7ca8
0260bff
571f788
2ca98ee
88a1706
ab36f0d
f1d21ba
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 |
---|---|---|
|
@@ -4,9 +4,13 @@ var fs = require('fs'); | |
var figures = require('figures'); | ||
var rimraf = require('rimraf'); | ||
var test = require('tap').test; | ||
var pkgConf = require('pkg-conf'); | ||
var Api = require('../api'); | ||
var testCapitalizerPlugin = require('./fixture/babel-plugin-test-capitalizer'); | ||
|
||
var conf = pkgConf.sync('ava'); | ||
var pkgDir = path.dirname(pkgConf.filepath(conf)); | ||
|
||
test('must be called with new', function (t) { | ||
t.throws(function () { | ||
var api = Api; | ||
|
@@ -18,6 +22,7 @@ test('must be called with new', function (t) { | |
generateTests('Without Pool: ', function (options) { | ||
options = options || {}; | ||
options.powerAssert = true; | ||
options.pkgDir = options.pkgDir || pkgDir; | ||
return new Api(options); | ||
}); | ||
|
||
|
@@ -63,6 +68,7 @@ generateTests('With Pool: ', function (options) { | |
options = options || {}; | ||
options.concurrency = 2; | ||
options.powerAssert = true; | ||
options.pkgDir = options.pkgDir || pkgDir; | ||
return new Api(options); | ||
}); | ||
|
||
|
@@ -307,12 +313,23 @@ function generateTests(prefix, apiCreator) { | |
}); | ||
}); | ||
|
||
test(prefix + 'change process.cwd() to a test\'s directory', function (t) { | ||
test(prefix + 'run from package.json folder by default', function (t) { | ||
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. This test doesn't do what you think it does. The Instead let's find the correct The next test is good (since it tests a non-default value). Just make sure not to accidentally break it with the aforementioned changes. 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. Ahh yeah, I see what you're saying. The fact that its even possible to create an Api() leading to an undefined pkgDir being given to fork is probably not a good idea. What about doing the following:
This would mean the test would work as expected, and test what it says - that if you just create an Api(), then it'll run from the package.json folder by default. 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. I changed things to reflect what I suggest here. The commit history is a bit of a mess now though, due to the rebase from master happening before a pull/push. My bad ^^ |
||
t.plan(1); | ||
|
||
var api = apiCreator(); | ||
|
||
return api.run([path.join(__dirname, 'fixture/process-cwd.js')]) | ||
return api.run([path.join(__dirname, 'fixture/process-cwd-default.js')]) | ||
.then(function (result) { | ||
t.is(result.passCount, 1); | ||
}); | ||
}); | ||
|
||
test(prefix + 'change process.cwd() to a test\'s directory with pkgDir', function (t) { | ||
t.plan(1); | ||
|
||
var fullPath = path.join(__dirname, 'fixture/process-cwd-pkgDir.js'); | ||
|
||
var api = apiCreator({pkgDir: path.dirname(fullPath)}); | ||
return api.run([fullPath]) | ||
.then(function (result) { | ||
t.is(result.passCount, 1); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import test from '../../'; | ||
import pkgConf from 'pkg-conf' | ||
import path from 'path' | ||
|
||
test(t => { | ||
var conf = pkgConf.sync('ava') | ||
var pkgDir = path.dirname(pkgConf.filepath(conf)) | ||
t.is(process.cwd(), pkgDir) | ||
}); |
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.
@alathon still seeing a diff here.
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.
Yes, there is a diff. But it lines up correctly in the terminal, when I execute it now. I'm not sure how to un-diff just that particular part of the file, although I know its possible through git.
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.
Well it renders the same so I'm not too bothered I suppose. @sindresorhus?
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.
They're different as you changed from tabs to spaces. They should remain spaces.
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.
I'll fix it on merge, but try not to do unrelated changes when doing a PR ;)
You could have uncommitted that part btw. Would be easiest to use a GUI git app for that. I use GitUp.app.