Skip to content

Commit

Permalink
Introduce dist/qunit-dom-modules.js
Browse files Browse the repository at this point in the history
Begins splitting things apart to be more compatible with not assuming
QUnit is am ambient global.
  • Loading branch information
rwjblue committed Sep 23, 2020
1 parent 4ddcf5c commit 1178cf8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 47 deletions.
35 changes: 35 additions & 0 deletions lib/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import DOMAssertions from './assertions';

declare global {
interface Assert {
dom(target?: string | Element | null, rootElement?: Element): DOMAssertions;
}
}

export default function (QUnit: QUnit) {
QUnit.assert.dom = function (
target?: string | Element | null,
rootElement?: Element
): DOMAssertions {
if (!isValidRootElement(rootElement)) {
throw new Error(`${rootElement} is not a valid root element`);
}

rootElement = rootElement || this.dom.rootElement || document;

if (arguments.length === 0) {
target = rootElement;
}

return new DOMAssertions(target, rootElement, this);
};

function isValidRootElement(element: any): element is Element {
return (
!element ||
(typeof element === 'object' &&
typeof element.querySelector === 'function' &&
typeof element.querySelectorAll === 'function')
);
}
}
5 changes: 5 additions & 0 deletions lib/qunit-dom-globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* global QUnit */

import install from './install';

install(QUnit);
4 changes: 4 additions & 0 deletions lib/qunit-dom-modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as QUnit from 'qunit';
import install from './install';

install(QUnit);
35 changes: 0 additions & 35 deletions lib/qunit-dom.ts

This file was deleted.

39 changes: 27 additions & 12 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import typescript from 'rollup-plugin-typescript2';

export default {
input: 'lib/qunit-dom.ts',
const typescriptConfiguration = {
exclude: [
'node_modules/**',
'lib/**/__tests__/**',
'lib/**/*.test.ts',
'lib/helpers/test-assertions.ts',
],
};

const iifeBundle = {
input: 'lib/qunit-dom-globals.ts',

external: ['qunit'],
plugins: [
typescript({
exclude: [
'node_modules/**',
'lib/**/__tests__/**',
'lib/**/*.test.ts',
'lib/helpers/test-assertions.ts',
],
}),
],
plugins: [typescript(typescriptConfiguration)],

output: {
file: 'dist/qunit-dom.js',
format: 'iife',
sourcemap: true,
},
};

const esBundle = {
input: 'lib/qunit-dom-modules.ts',

external: ['qunit'],
plugins: [typescript(typescriptConfiguration)],

output: {
file: 'dist/qunit-dom.es.js',
format: 'es',
sourcemap: true,
},
};

export default [iifeBundle, esBundle];

0 comments on commit 1178cf8

Please sign in to comment.