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

add test case for bare import specifiers #53

Closed
thescientist13 opened this issue Jun 5, 2022 · 0 comments · Fixed by #70
Closed

add test case for bare import specifiers #53

thescientist13 opened this issue Jun 5, 2022 · 0 comments · Fixed by #70
Labels
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jun 5, 2022

Type of Change

  • Other (please clarify below)

Summary

As part of #44 , I tried adding test cases to the PR, but they kept failing, and I think it is related to #24 .

Details

Would like to add a test case though to ensure this works as expected ASAP. Here is what I had originally - #44

Make sure to install node-fetch as a devDependency

// ./components/events-list.js
import fetch from 'node-fetch';

class EventsList extends HTMLElement {
  async connectedCallback() {
    if (!this.shadowRoot) {
      // TODO should probably try and make this a JSON file
      const events = await fetch('http://www.analogstudios.net/api/v2/events').then(resp => resp.json());

      this.attachShadow({ mode: 'open' });
      this.shadowRoot.innerHTML = `<h1>Events List (${events.length})</h1>`;
    }
  }
}

export {
  EventsList
};

customElements.define('wc-events-list', EventsList); 
// index.js
import './components/events-list.js';

export default class HomePage extends HTMLElement {
  constructor() {
    super();

    if (this.shadowRoot) {
      // console.debug('HomePage => shadowRoot detected!');
    } else {
      this.attachShadow({ mode: 'open' });
    }
  }

  connectedCallback() {
    this.shadowRoot.innerHTML = this.getTemplate();
  }

  getTemplate() {
    return `
      <wc-events-list></wc-events-list>
    `;
  }
} 
// node-modules.spec.js
/*
 * Use Case
 * Run wcc against a custom element using a dependency from node-modules
 *
 * User Result
 * Should run without error.
 *
 * User Workspace
 * src/
 *   components/
 *     events-list.js
 *   index.js
 */
import { renderToString } from '../../../src/wcc.js';

describe('Run WCC For ', function() {
  const LABEL = 'Custom Element w/ a node modules dependency';

  describe(LABEL, function() {
    it('should not fail when the content load a node module', function() {
      Promise.resolve(renderToString(new URL('./src/index.js', import.meta.url)));
    });
  });
}); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant