Skip to content

Conversation

@rkostrzewski
Copy link
Collaborator

Basic tests for every command CLI exposes 🎉

Stuff used:

  • Headless chrome (which requires Chrome > 59)
  • Tape - Jest had problems with running Chrome, Ava had problems with spawning - tests are kinda slow without concurrency (~1m on my laptop).

Stuff changed:

  • Added option to preact create not to install dependencies

@rkostrzewski rkostrzewski requested review from developit and lukeed June 10, 2017 22:37
Copy link
Member

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome stuff looks really cool!

I'm also not sure that there's a need for async-test at all. The test function accepts an opts.timeout value which defaults to 500.

test('possibly long test', { timeout:30000 }, async t => {
  // ...
});

Feel free to disregard anything 😉 Thanks for taking the time to do all this!

] : [])
].filter(Boolean));
}
spinner.text = 'Installing dependencies';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to move this all under the same if (argv.install). Plus, right now this will display "Installing deps..." when install = false.

'sw.js': { size: 3905 }
};

const expectedOutputs = prepare({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can totally disregard this, but I typically like to move "expectants" of this size to a separate fixture file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right - just being lazy 😛 I was thinking about some snapshots but the only package i found didn't work

const listOutput = async dir => await lsr(dir, ['.gitkeep', 'package.json']);

test('preact create - before', async () => {
await setup();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also prefer to move all the setup()s and clean()s into the test itself, since the presence of async will ensure that those prep/teardowns happen accordingly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated them because it the 'main' test fails then they will be called for sure.

It doesn't matter for create or build that much (they could be handled inside tests and in test.onFinish hook), but stuff with chrome get's trickier as we must ensure service worker is unregistered after tests because on non-CI environment service workers could provide false positives (I've tried using profile flag to ensure clean state to no avail).

I thought that consistency between all tests would be easier to maintain & extend.


export const outputPath = resolve(__dirname, '../output');

export const setup = async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these can just be:

export const name = () => helper(foo);

since they are returning Promises & will be/are awaited in the tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what you get for writing in language with native async & await for years. 😅

@rkostrzewski
Copy link
Collaborator Author

@lukeed I was afraid of DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.. Since tape doesn't care about returned promises async-test takes care of that.

opts.timeout looks good - I'll definitely use it!

@lukeed
Copy link
Member

lukeed commented Jun 10, 2017

Where does that DeprecationWarning show up?

@rkostrzewski
Copy link
Collaborator Author

It comes right out of node in console when async test fails using regular tape test.

@lukeed
Copy link
Member

lukeed commented Jun 10, 2017

Oh sorry, I meant a specific test as an example 😃

@rkostrzewski
Copy link
Collaborator Author

Then any test hopefully never 😄

lukeed
lukeed previously approved these changes Jun 11, 2017
Copy link
Member

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! 👍 My only suggestion now is to just write a timeout:Number directly into the async-test so that you don't have to define an options object on only some of the tests.

Plus, having the shared timeout won't affect any tests negatively, since the ones that currently don't have a timeout are expected to finish quickly.

Well done!

developit
developit previously approved these changes Jun 11, 2017
Copy link
Member

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically perfect, I have no valuable comments to add lol.

type: 'boolean',
default: false
},
install: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call.


await fs.writeFile(path.resolve(target, 'package.json'), JSON.stringify(pkg, null, 2));

spinner.text = 'Installing dev dependencies';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitpick (feel free to ignore) - seems like the dev dep message and "done!" message should be inside the if here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misread the diff last time. Yeah, ^^ what I was trying to say last time. 😴

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I wanted to change it like that! Anyway, should be good now 😆

@developit
Copy link
Member

@rkostrzewski @lukeed think we're good to merge? It'd be great to have these running on Travis. To that end, I just enabled travis for the preact-cli repo. I think updating this branch will trigger a build and we can check that everything is peachy there.

@rkostrzewski
Copy link
Collaborator Author

rkostrzewski commented Jun 11, 2017

@developit hold on I'll work on setting up travis on this branch - I've got a feeling it won't be so easy (I bet timeouts will have to be increased 😝 )

@lukeed I was afraid that on CI dev server tests will run for more than a minute and timeout will get large and could negatively affect hanging tests on PRs (like waiting 15minutes to get result etc).

@rkostrzewski rkostrzewski dismissed stale reviews from developit and lukeed via 7800035 June 11, 2017 20:17
@rkostrzewski
Copy link
Collaborator Author

...many commits later....

It's green! 🎉 😀 I've restarted the build several times to make sure it is reliable.

@lukeed assuming you mean sth like test('Name', 500, async t => I'll leave it like it is - I think current approach with async test having same API as tape test is more versatile.

@developit I think we're ready to merge! 😀

BTW we can install yarn on travis after yarn PR makes it way and use it to create app - maybe the install switch could be removed

@developit
Copy link
Member

That's awesome :D

@rkostrzewski
Copy link
Collaborator Author

| rkostrzewski dismissed stale reviews from @developit and @lukeed via 7800035 9 days ago
😢 any of you mind doing it again? 🙏

developit
developit previously approved these changes Jun 23, 2017
Copy link
Member

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one question about sleep

let { listeners } = await DOMDebugger.getEventListeners({ objectId: object.objectId });

if (!listeners.some(l => l.type === 'click')) {
await pageIsInteractive(chrome, retryCount - 1, retryInterval);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be missing an await sleep(retryInterval)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preact sure is fast as it didn't ever fail on CI AFAIR. 😄 I'll add the delay with smaller interval

Copy link
Collaborator Author

@rkostrzewski rkostrzewski Jun 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done so here.

Is there any trick not to dismiss reviews when committing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, maybe it's a setting..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, just turned that thing off. sorry!

Copy link
Member

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rkostrzewski rkostrzewski added this to the 1.2.0 milestone Jun 23, 2017
@rkostrzewski rkostrzewski merged commit bf62766 into master Jun 23, 2017
@rkostrzewski rkostrzewski deleted the feature/cli-tests branch June 23, 2017 15:58
@lukeed
Copy link
Member

lukeed commented Jun 23, 2017

🙌 🕺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants