Skip to content

Commit 3550311

Browse files
authoredNov 25, 2021
Merge pull request #25 from getmimo/move-helper-to-sphinx-instead
move helper function into sphinx library instead
2 parents bd4b364 + b80b4ed commit 3550311

File tree

6 files changed

+51
-53
lines changed

6 files changed

+51
-53
lines changed
 

‎dist/falcon/index.js

-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict';
22
const deepEqual = require('deep-equal');
3-
const jsdom = require('jsdom');
4-
const { JSDOM } = jsdom;
5-
let path = require('path');
63

74
// The stack of beforeEach callbacks
85
const beforeEachStack = [[]];
@@ -84,26 +81,3 @@ const isEqual = (actual, expected) => {
8481
}
8582
return actual;
8683
};
87-
88-
// HELPER
89-
async function domLoaded(file) {
90-
return JSDOM.fromFile(path.resolve(file), {
91-
resources: 'usable',
92-
runScripts: 'dangerously',
93-
}).then(async (dom) => {
94-
return await new Promise((resolve, reject) => {
95-
dom.window.document.addEventListener('DOMContentLoaded', () => {
96-
resolve(dom);
97-
});
98-
});
99-
});
100-
}
101-
102-
module.exports = {
103-
test,
104-
end,
105-
beforeEach,
106-
summary,
107-
isEqual,
108-
domLoaded,
109-
};

‎dist/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
declare const $: any;
2+
declare const jsdom: any;
3+
declare const JSDOM: any;
4+
declare let path: any;
25
declare class Sphinx {
36
private code;
47
private root;
@@ -75,3 +78,4 @@ declare function isTextSimilar(root: any, elementName: any, text: any): any;
7578
declare function isAttributeSet(root: any, elementName: any, attributeName: any, attributeValue: any): boolean;
7679
declare function buildSphinx(root: any, htmlCode: string, test: any, expect: any): Sphinx;
7780
declare function buildSphinxWithJSDOM(test: any, expect: any): Sphinx;
81+
declare function domLoaded(file: any): Promise<any>;

‎dist/index.js

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎falcon/index.js

-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict';
22
const deepEqual = require('deep-equal');
3-
const jsdom = require('jsdom');
4-
const { JSDOM } = jsdom;
5-
let path = require('path');
63

74
// The stack of beforeEach callbacks
85
const beforeEachStack = [[]];
@@ -84,26 +81,3 @@ const isEqual = (actual, expected) => {
8481
}
8582
return actual;
8683
};
87-
88-
// HELPER
89-
async function domLoaded(file) {
90-
return JSDOM.fromFile(path.resolve(file), {
91-
resources: 'usable',
92-
runScripts: 'dangerously',
93-
}).then(async (dom) => {
94-
return await new Promise((resolve, reject) => {
95-
dom.window.document.addEventListener('DOMContentLoaded', () => {
96-
resolve(dom);
97-
});
98-
});
99-
});
100-
}
101-
102-
module.exports = {
103-
test,
104-
end,
105-
beforeEach,
106-
summary,
107-
isEqual,
108-
domLoaded,
109-
};

‎src/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const $ = require('jquery');
2+
const jsdom = require('jsdom');
3+
const { JSDOM } = jsdom;
4+
let path = require('path');
25

36
class Sphinx {
47
private code: string;
@@ -400,11 +403,26 @@ function buildSphinxWithJSDOM(test: any, expect: any) {
400403
return new Sphinx(undefined, undefined, test, expect);
401404
}
402405

406+
// HELPER
407+
async function domLoaded(file) {
408+
return JSDOM.fromFile(path.resolve(file), {
409+
resources: 'usable',
410+
runScripts: 'dangerously',
411+
}).then(async (dom) => {
412+
return await new Promise((resolve, reject) => {
413+
dom.window.document.addEventListener('DOMContentLoaded', () => {
414+
resolve(dom);
415+
});
416+
});
417+
});
418+
}
419+
403420
module.exports = {
404421
buildSphinx: buildSphinx,
405422
buildSphinxWithJSDOM: buildSphinxWithJSDOM,
406423
isTextSet: isTextSet,
407424
isTextEqual: isTextEqual,
408425
isTextSimilar: isTextSimilar,
409426
isAttributeSet: isAttributeSet,
427+
domLoaded,
410428
};

0 commit comments

Comments
 (0)
Please sign in to comment.