2020-04-28 09:47:35 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
|
|
import buble from '@rollup/plugin-buble';
|
|
|
|
|
|
|
|
const match = '-test.ts';
|
2021-01-12 12:04:19 +00:00
|
|
|
|
|
|
|
// Find files
|
|
|
|
let files = fs
|
2020-04-28 09:47:35 +00:00
|
|
|
.readdirSync('tests')
|
|
|
|
.sort()
|
2021-01-12 12:04:19 +00:00
|
|
|
.filter((file) => file.slice(0 - match.length) === match);
|
|
|
|
|
|
|
|
// Remove suffix
|
|
|
|
files = files.map((file) => file.slice(0, file.length - match.length));
|
|
|
|
|
|
|
|
// Debug one test
|
|
|
|
// files = ['21-scan-dom-api'];
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Get config files
|
|
|
|
const tests = [];
|
2021-01-12 12:04:19 +00:00
|
|
|
const config = files.map((file) => {
|
2020-04-28 09:47:35 +00:00
|
|
|
tests.push(file + '.js');
|
|
|
|
return {
|
|
|
|
input: 'lib/' + file + match.replace('.ts', '.js'),
|
|
|
|
output: {
|
|
|
|
file: 'dist/' + file + '.js',
|
|
|
|
format: 'iife',
|
|
|
|
globals: {
|
|
|
|
mocha: 'mocha',
|
|
|
|
chai: 'chai',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
external: ['mocha', 'chai'],
|
|
|
|
plugins: [
|
|
|
|
resolve({
|
|
|
|
browser: true,
|
|
|
|
extensions: ['.js'],
|
|
|
|
}),
|
2021-01-12 12:04:19 +00:00
|
|
|
commonjs({
|
|
|
|
ignore: ['cross-fetch'],
|
|
|
|
}),
|
2021-05-24 10:25:02 +00:00
|
|
|
buble({
|
|
|
|
objectAssign: 'Object.assign',
|
|
|
|
}),
|
2020-04-28 09:47:35 +00:00
|
|
|
],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// Write tests.html
|
|
|
|
let content = fs.readFileSync(__dirname + '/tests/tests.html', 'utf8');
|
|
|
|
content = content.replace(
|
|
|
|
'<!-- tests -->',
|
|
|
|
tests
|
2021-01-12 12:04:19 +00:00
|
|
|
.map((file) => {
|
2020-04-28 09:47:35 +00:00
|
|
|
return '<script src="./' + file + '"></script>';
|
|
|
|
})
|
|
|
|
.join('')
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
fs.mkdirSync(__dirname + '/dist', 0o755);
|
|
|
|
} catch (err) {}
|
|
|
|
fs.writeFileSync(__dirname + '/dist/tests.html', content, 'utf8');
|
|
|
|
|
|
|
|
export default config;
|