Conversation
|
Saw this, looks pretty good! Here's some initial questions:
|
|
@ariporad all tests should be working for describe('before doing plugin', () => {
it('does not exist before being registered', () => {
t.is(!shell.foo);
});
});
describe('before doing plugin', () => {
beforeEach(() => {
plugin.register('foo', fooImplementation, {
cmdOptions: {
'f': 'flag',
},
wrapOutput: true,
canReceivePipe: true,
});
});
afterEach(() => {
// do something to un-register the plugin
});
it('exists after registering', () => {
t.is(shell.foo);
});
});I'm not sure what the equivalent of |
test/dirs.js
Outdated
|
|
||
| test('Clearing items', t => { | ||
| t.deepEqual(shell.dirs('-c'), []); | ||
| assert(!shell.error()); |
There was a problem hiding this comment.
Oops... I forgot to fix this.
There was a problem hiding this comment.
No worries, it should be resolved now. Simple regex 😄
|
@nfischer: Wow... you did a lot! Your questions, in order:
I'm going to be busy till tomorrow morning, but I'll try to review everything then. |
|
@ariporad would we be able to serialize the tests within |
|
@ariporad I'll leave the rest of this to you, since there shouldn't be much more. Ping me on here when it's ready for review 😄 |
|
@nfischer: Ok, this should be good now, it all passes lint. I don't have a way to test on windows, but otherwise should be good. |
|
@ariporad the tests are failing because we used to skip some tests when running on Windows ( test('title', t => {
if (windows) return;
// otherwise proceed as normal
}); |
test/which.js
Outdated
|
|
||
| if (process.platform === 'win32') { | ||
| // TODO: Why are we skipping this? | ||
| windows.skip('No Test Title #60', t => { |
There was a problem hiding this comment.
This is incorrect. This test only works on Windows, not Unix. You're skipping on Windows and running it on Unix.
test/which.js
Outdated
| } | ||
|
|
||
| shell.exit(123); | ||
| t.is(node + '', nodeExe + ''); |
There was a problem hiding this comment.
Could you change this to node.toString() and nodeExe.toString()? I think that would make the meaning more clear. A simple regex should catch all occurrences of this.
test/cp.js
Outdated
| test('dest already exists', t => { | ||
| const oldContents = shell.cat('resources/file2').toString(); | ||
| const result = shell.cp('-n', 'resources/file1', 'resources/file2'); // dest already exists | ||
| t.truthy(!shell.error()); |
There was a problem hiding this comment.
Could we convert t.truthy(!expr); to t.falsy(expr);? It should be a bit more readable.
test/exec.js
Outdated
| t.is(result.stderr, ''); | ||
| }); | ||
|
|
||
| test.todo('set shell option for windows'); |
test/exec.js
Outdated
| test.cb('callback as 2nd argument', t => { | ||
| shell.exec(JSON.stringify(process.execPath) + ' -e "console.log(5678);"', function (code, stdout, stderr) { | ||
| t.is(code, 0); | ||
| t.truthy(stdout === '5678\n'); |
There was a problem hiding this comment.
Can you change this to t.is(stdout, '5678\n');?
test/exec.js
Outdated
| shell.exec(JSON.stringify(process.execPath) + ' -e "console.log(5678);"', function (code, stdout, stderr) { | ||
| t.is(code, 0); | ||
| t.truthy(stdout === '5678\n'); | ||
| t.truthy(stderr === ''); |
test/exec.js
Outdated
| }); | ||
| t.is(code2, 0); | ||
| t.truthy(stdout2 === '5566\n'); | ||
| t.truthy(stderr2 === ''); |
test/exec.js
Outdated
| shell.exec(JSON.stringify(process.execPath) + ' -e "console.log(5678);"', { silent: true }, function (code3, stdout3, stderr3) { | ||
| t.is(code3, 0); | ||
| t.truthy(stdout3 === '5678\n' || stdout3 === '5678\nundefined\n'); // 'undefined' for v0.4 | ||
| t.truthy(stderr3 === '' || stderr3 === 'undefined\n'); // 'undefined' for v0.4 |
|
@ariporad are we still working on this? If so, would you be able to rebase this off master? |
31a96f3 to
b9c37ab
Compare
|
@freitagbr (and any one else), feel free to help take this on. Tests are still very flaky when run in parallel mode. |
|
Also, here's a running list of the files I've verified have not lost any test cases during the refactor:
|
|
I think I know why the tests are failing. Let's look at let TMP;
test.beforeEach(() => {
TMP = utils.getTempDir();
shell.config.silent = true;
shell.cp('-r', 'resources', TMP);
});Isn't the value of In other words, we can't have any globals in these async tests. That, or we keep a stack or something of all the tmp directories that get created. |
|
Solution to the problem, do something like this: test.beforeEach(t => {
const tmp = t.context.tmp = utils.getTempDir();
shell.config.silent = true;
shell.cp('-r', 'resources', tmp);
});
test('example' t => {
// t.context.tmp is the tmp dir for this test
}); |
|
@freitagbr ah, that looks perfect. That's just what I was looking for. I'll do the refactor tonight and push again |
|
@nfischer I already wrote the code to test it. Can I submit a PR to this branch? |
|
Even after fixing that bug, I still get an error: |
|
@freitagbr whoops, didn't see your comment. Take a look at the commit I just uploaded here. If I missed anything, feel free to correct it |
|
Alright. Since we're starting to get merge conflicts with other patches that are going through, and I'm tired of rebasing, I think we should start merging these files one at a time. Here's the proposed strategy to do this in a sane way:
Once all tests are refactored like this, we just do @freitagbr what are your thoughts on this plan? |
|
I think that's a good plan. Just keep an eye community contributions, they might get confused as to where their tests should go. |
|
Closing this, since we're almost done migrating all the tests |
This PR switches our tests to AVA. It's very much still a work in progress.
Because switching to a whole new testing framework is a very large task, this was all done with a codemod (basically, a babel plugin which re-writes our tests. It's in the
codemodsfolder if you're interested). Immediately after running the codemod, ~2/3 of our tests passed with AVA. (Which is pretty good). The rest are going to have to be fixed by hand (still waaay faster than doing it all manually).I'll be continually updating this PR as I fix more of the tests.
I'm opening this PR so early in the process because:
Things which need to get done:
avatopackage.jsonas a devDependency and as thenpm run testscript.@@TEST)chmod)