Skip to content

Try mocha/chai test runners#1418

Merged
drwpow merged 8 commits intonextfrom
next-mocha
Sep 23, 2021
Merged

Try mocha/chai test runners#1418
drwpow merged 8 commits intonextfrom
next-mocha

Conversation

@drwpow
Copy link
Member

@drwpow drwpow commented Sep 23, 2021

Changes

In switching to Vite and having to rework tests with the new compiler, I took the opportunity to revisit our test runner. Since Jest had just released ESM support, it seemed like a good option. The biggest motivator for switching from uvu -> Jest is simply contributor familiarity; I wanted to prioritize reducing the barrier to contribute testing using what most JS devs are familiar with. But other benefits were timeouts, clearer errors, more utilities, and an overall more stable runner. Fortunately Jest worked! 🎉 … But only locally 😑. It has not been passing CI.

This PR switches to Mocha / Chai, again with the priority of “use what most people know.” This is the closest thing to Jest, and if you know Jest you probably can pick this up quickly.

Basically:

Before

Screen Shot 2021-09-23 at 14 53 18

After

Screen Shot 2021-09-23 at 14 53 15

Testing

Testing PR.

Docs

@drwpow drwpow requested a review from a team as a code owner September 23, 2021 18:14
@vercel
Copy link

vercel bot commented Sep 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

astro-www – ./www

🔍 Inspect: https://vercel.com/pikapkg/astro-www/HBpt55dX6CsNQtds4jDa6ZEnP6Gk
✅ Preview: Canceled

[Deployment for 2d80feb canceled]

astro-docs – ./docs

🔍 Inspect: https://vercel.com/pikapkg/astro-docs/41DmdcKBfDSZVEChd7fx3Kx5NBJS
✅ Preview: Canceled

[Deployment for 2d80feb canceled]

@changeset-bot
Copy link

changeset-bot bot commented Sep 23, 2021

⚠️ No Changeset found

Latest commit: 2d80feb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:17 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:17 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:21 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:21 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:33 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:33 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:51 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:51 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:51 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:51 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:51 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:51 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 18:52 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 18:52 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 20:08 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 20:08 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 20:16 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 20:16 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 20:23 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 20:23 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 20:41 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 21:55 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 21:55 Inactive
- name: "Smoke Test: Build 'www'"
run: yarn build
working-directory: ./www
# NOTE: temporarily disabled until `next` branch can build docs again
Copy link
Member Author

Choose a reason for hiding this comment

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

Temporarily disabled docs build test until we get a little farther

}

export const createComponent = (cb: AstroComponentFactory) => {
export function createComponent(cb: AstroComponentFactory) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Minor code style nit: I think functions are generally better because they all get hoisted and don’t depend on order of definition like const does

@@ -1,41 +0,0 @@
import type { AstroComponent, AstroComponentFactory } from '../internal';

import { spreadAttributes, defineStyleVars, defineScriptVars } from '../internal';
Copy link
Member Author

Choose a reason for hiding this comment

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

This file was deleted because this introduced a circular dependency between src/runtime/astro.ts and src/internal/index.ts. This was just moved into internal.

Naming is hard.

async function resolveImportedModules(viteServer: ViteDevServer, file: string) {
const { url } = await viteServer.moduleGraph.ensureEntryFromUrl(file);
async function resolveImportedModules(viteServer: ViteDevServer, file: URL) {
const { url } = await viteServer.moduleGraph.ensureEntryFromUrl(slash(fileURLToPath(file))); // note: for some reason Vite expects forward slashes here for Windows, which `slash()` helps resolve
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun Windows Vite bug! 🎉 New test runner caught it.

expect($('#true').attr('type')).toBe('boolean');
expect($('#false').attr('attr')).toBe('attr-false');
expect($('#false').attr('type')).toBe('boolean');
expect($('#true').attr('attr')).to.equal('attr-true');
Copy link
Member Author

Choose a reason for hiding this comment

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

Mocha + Chai was selected because of its similarity to Jest. Migrating was just a quick find-and-replace.

@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 22:07 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 22:07 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 22:16 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 22:16 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 22:28 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 22:28 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 22:55 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 22:55 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-www September 23, 2021 23:00 Inactive
@vercel vercel bot temporarily deployed to Preview – astro-docs September 23, 2021 23:00 Inactive
@FredKSchott
Copy link
Member

AMAZING, nice work

@jasikpark
Copy link
Contributor

Nice! I've had a great experience w/ Ava in https://github.com/snowpackjs/prettier-plugin-astro - it's fully ESM in Avajs 4.0 & has a similar setup to uvu, but is much more reliable!

https://github.com/avajs/ava

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.

3 participants