Newtonian Physics Mockumentary
Miss any of our Open RFC calls?Watch the recordings here! »

@dxworks/linting

0.0.9 • Public • Published

Linting

This package includes linting configuration, a base ava configuration, and two ava helpers.

Configs

prettier

const { prettierrc } = require('@dxworks/linting');
module.exports = prettierrc;

eslint

const { eslintrc } = require('@dxworks/linting');
module.exports = eslintrc;

ava

import { config } from '@dxworks/linting/ava.config';
 
export default {
  ...config,
};

Helpers

withPage()

Forked from ava's puppeteer recipe this helper function let's you use puppeteer with ava. Be sure to add puppeteer to package.json devDependencies to use

example

import test from 'ava';
import { withPage } from '@dxworks/linting/helpers';
 
const url = 'https://google.com';
 
test('page title should contain "Google"', withPage, async (t, page) => {
  await page.goto(url);
  t.true((await page.title()).includes('Google'));
});
 
test('page should contain an element with `#hplogo` selector', withPage, async (t, page) => {
  await page.goto(url);
  t.not(await page.$('#hplogo'), null);
});
 
test('search form should match the snapshot', withPage, async (t, page) => {
  await page.goto(url);
  const innerHTML = await page.evaluate(form => form.innerHTML, await page.$('#searchform'));
  t.snapshot(innerHTML);
});

bundleModules()

This function is useful for when you want to bundle the Custom Element you're testing and expose it to puppeteer via the page.addScriptTag method. It is best used in conjunction with the withPage helper.

Note: The paths passed to bundleModules() are relative to where you call your test script from, usually the root of your project.

example

import test from 'ava';
import { withPage, bundleModules } from '@dxworks/linting/helpers';
 
test(
  `Given a tag and template, Should create a custom element
  with that template content`,
  withPage,
  async (t, page) => {
    const bundle = await bundleModules('src/createLight/createLight.js', 'src/render/render.js');
    await page.addScriptTag({ content: bundle });
    const wrapper = await page.evaluate(() => {
      const { createLight, render } = window.$x;
      createLight({
        tag: 'example-component',
        component: base =>
          class extends base {
            connectedCallback() {
              super.connectedCallback();
              render({ context: this, template: () => '<div>example component</div>' });
            }
          },
      });
      const body = document.querySelector('body');
      const fragment = document.createElement('example-component');
      body.appendChild(fragment);
      return document.querySelector('example-component').outerHTML;
    });
    t.is(wrapper, '<example-component><div>example component</div></example-component>');
  },
);

Keywords

none

Install

npm i @dxworks/[email protected]

Version

0.0.9

License

MIT

Unpacked Size

8.17 kB

Total Files

12

Last publish

Collaborators

  • avatar
  • avatar