Skip to content
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

Make module server configurable #163

Merged
merged 7 commits into from
Jul 20, 2021
Merged

Make module server configurable #163

merged 7 commits into from
Jul 20, 2021

Conversation

calebeby
Copy link
Member

@calebeby calebeby commented Jul 15, 2021

Closes #140

The code is all ready for review. I didn't update the README yet.

This makes it possible to configure the module server in each test. You could inject additional rollup plugins, etc. An example of this is to add a plugin to load Vue SFC's:

import vuePlugin from 'rollup-plugin-vue'
test(
  'vue component can be imported via rollup-plugin-vue',
  withBrowser(
    {
      moduleServer: {
        plugins: [vuePlugin()],
      },
    },
    async ({ utils, screen }) => {
      await utils.injectHTML('<div id="app"></div>')
      await utils.runJS(`
	    import { createApp } from 'vue'
	    import VueComponent from './vue-component.vue'
	    const app = createApp(VueComponent)
	    app.mount('#app')
	  `)
      const heading = await screen.getByRole('heading')
      await expect(heading).toHaveTextContent('Hiya')
      await expect(heading).toHaveStyle({ color: 'green' })
    },
  ),
)

There is also a configureDefaults function exported by pleasantest, so you don't have to set the options for each test individually:

import { withBrowser, configureDefaults } from 'pleasantest'

configureDefaults({
  moduleServer: {
    plugins: [vuePlugin()],
  },
})

There is also an internal change: File ids (used by the rollup plugins) are now absolute paths once they are resolved. This was changed to match Rollup's default behavior, and it fixed a compatibility issue with rollup-plugin-vue. So the ids start out as url's, which are relative to the project root, then they get converted to absolute paths, and run through all the plugins, and at the very end before the module is served they get converted back into paths that are relative to the project root.

Copy link
Contributor

@Paul-Hebert Paul-Hebert 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 a killer feature @calebeby !

I'm still wrapping my head around this codebase, but these changes seem reasonable 👍 One nitpick about an error message inline.

Copy link
Member

@gerardo-rodriguez gerardo-rodriguez left a comment

Choose a reason for hiding this comment

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

Super cool feature, great work, @calebeby!

I'm in the same boat as @Paul-Hebert where I don't understand every line of code fully but overall, the code looks good! Pending the suggestion from Paul, I approve!

@calebeby
Copy link
Member Author

Thanks for the reviews @Paul-Hebert and @gerardo-rodriguez! Do you mind taking a look at the README changes that I just pushed as well?

@Paul-Hebert
Copy link
Contributor

@calebeby the README info looks good! I left a couple questions inline.

@calebeby calebeby merged commit 248376d into main Jul 20, 2021
@calebeby calebeby deleted the configurable-module-server branch July 20, 2021 20:11
@github-actions github-actions bot mentioned this pull request Jul 20, 2021
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.

Make module server configurable
3 participants