Closed tomitrescak closed 3 years ago
This is another config I tried:
// @ts-nocheck1
// eslint-disable-next-line @typescript-eslint/no-var-requires
module.exports = function (wallaby) {
return {
files: ['src/compilers/python/**/*.ts', '!src/compilers/python/**/*.test.ts'],
tests: ['src/compilers/python/**/*.test.ts'],
testFramework: 'mocha',
compilers: {
'**/*.ts?(x)': wallaby.compilers.babel({
presets: ['next/babel'],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }]
]
})
},
env: {
type: 'node',
runner: 'node'
},
setup: function (wallaby) {
const { JSDOM } = require('jsdom');
const options = {
runScripts: 'dangerously',
resources: 'usable'
};
global.window = new JSDOM(
`
<!DOCTYPE html><html><body><div id="test"></div><script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js"></script></body></html>
`,
options
);
}
};
};
For browser-based tests (NOT using node), this should work for you with the wallaby-typescript-sample
:
wallaby.js
module.exports = function (w) {
return {
files: ['src/index.html', 'src/*Browser.ts'],
tests: ['test/*BrowserSpec.ts'],
setup: function () {
// return a promise and don't resolve/reject it until the CDN script has loaded.
return new Promise(function (resolve, reject) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.onload = resolve;
script.onerror = reject;
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js';
head.appendChild(script);
});
},
};
};
I'm going to take a quick look to see if you can do a similar thing with JSDOM.
I can't seem to get JSDOM to load brython. If you want to take this approach, you should try get it loading outside of Wallaby first.
I should also note that it's less than ideal to go and download from the CDN each time, even if it is cached. As a best practice, we recommend downloading the library for when your tests are running, even if this isn't what you do in your production runtime. It will be faster and less fragile.
Thank you very much @smcenlly
Issue description or question
Hi, I'm trying to run tests where I need to load some global scripts (not require), but I'm failing. I tried via node.js and jsdom but it did not work. I tried with pure browser exaplme from 'https://github.com/wallabyjs/wallaby-typescript-sample/' but again no luck.
When I run my simple test:
I get this error:
My secon question would be: how can I include scripts that are loaded in the page, such as
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js"></script>
Tank you!
Wallaby diagnostics report