Skip to content

Commit

Permalink
add rollup case
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 21, 2023
1 parent 9ab0d39 commit 60cc9b1
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 32 deletions.
49 changes: 47 additions & 2 deletions scripts/build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ const path = require('path');
const esbuild = require('esbuild');
const webpack = require('webpack');

const { rollup } = require('rollup');
const rollupTypescript = require('@rollup/plugin-typescript');
const rollupCommonJs = require('@rollup/plugin-commonjs');

const EC = require('eight-colors');

const webpackConfIstanbul = require('../test/webpack.config-istanbul.js');
const webpackConfV8 = require('../test/webpack.config-v8.js');


const startWebpack = function(conf) {
return new Promise(function(resolve) {
webpack(conf, (err, stats) => {
Expand Down Expand Up @@ -83,11 +86,53 @@ const runEsbuild = async () => {
console.log(EC.green('finish esbuild'));
};

const runRollup = async () => {

const entry = path.resolve('test/mock/src/index.js');

const inputOptions = {
input: entry,
plugins: [
rollupCommonJs(),
rollupTypescript({
sourceMap: true,
inlineSources: true
})
]
};

const outputOptions = {
file: path.resolve('test/mock/rollup/dist/coverage-rollup.js'),
name: 'coverageRollup',
format: 'iife',
sourcemap: true
};

let bundle;
let buildFailed = false;
try {
// create a bundle
bundle = await rollup(inputOptions);

await bundle.write(outputOptions);
console.log(EC.green('finish rollup'));

} catch (error) {
buildFailed = true;
// do some error reporting
console.error(error);
}
if (bundle) {
// closes the bundle
await bundle.close();
}
process.exit(buildFailed ? 1 : 0);
};
const build = async () => {
await runWebpackIstanbul();
await runWebpackV8();
await runEsbuild();

await runRollup();

};

Expand Down
14 changes: 7 additions & 7 deletions test/mock/minify/comments.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable no-trailing-spaces,line-comment-position,no-inline-comments,indent,no-multi-spaces,no-multiple-empty-lines */
// LineComment

console.log('some//thing'); // comment /*
console.log('some"//"\\\'thing\\'); // comment /*

// comment /*
console.log('some//thing/*'); /*
// comment /* ---
console.log('some//thing/*'); /*
ddd
*/
console.log('some/*/thing');

//
console.log(`
/*
//
*/
'/*
"//"
*/'
`);

/**
Expand Down
19 changes: 19 additions & 0 deletions test/mock/rollup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>coverage page</title>
<link href="../minify/style.css" rel="stylesheet" />
</head>

<body>
<h3 class="red inline-used and-used">
Mock V8 Rollup Coverage
</h3>
<script src="dist/coverage-rollup.js"></script>
</body>

</html>
8 changes: 4 additions & 4 deletions test/mock/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import './branch.js';
import './typescript.ts';

import '../minify/comments.js';
import '../minify/demo.js';

import './branch.js';
import ts from './typescript.ts';

export function foo(argument) {
console.log('this is foo');

Expand Down Expand Up @@ -96,4 +96,4 @@ const onload = (something) => {
};

// one line but two statements
init(window._my_stop_key); onload(window._my_something);
init(window._my_stop_key); onload(window._my_something); ts();
30 changes: 16 additions & 14 deletions test/mock/src/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
var str: string = "hello world";

// point type
type Point = {
x: number,
y: number
}

var p: Point = {
x: 1,
y: 2
}

var fun = (v: Point) => {
console.log(v);
const fun = (p: Point, pointIn: Point) => {
const str: string = "hello world";
console.log(p, pointIn, str);
return str;
}

fun(p);

var main = (p: Point, v: string) => {
const main = (p: Point, s: string) => {
/*
block comment
typescript block comment
*/
const pointIn: Point = {
x: 1,
y: 2
}

// typescript line comment

const v = fun(p, pointIn);

console.log(p, v);
console.log(p, s, v);

}

module.exports = main;
export default main;
19 changes: 19 additions & 0 deletions test/mock/vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>coverage page</title>
<link href="../minify/style.css" rel="stylesheet" />
</head>

<body>
<h3 class="red inline-used and-used">
Mock V8 Vite Coverage
</h3>
<script src="dist/coverage-vite.js"></script>
</body>

</html>
3 changes: 3 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"author": "",
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-typescript": "^11.1.5",
"babel-loader": "^9.1.3",
"babel-plugin-istanbul": "^6.1.1",
"esbuild": "^0.19.10",
Expand All @@ -16,6 +18,7 @@
"koa-static-resolver": "^1.0.4",
"marked": "^11.1.0",
"playwright": "^1.40.1",
"rollup": "^4.9.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.89.0"
Expand Down
2 changes: 1 addition & 1 deletion test/test-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const generate = async () => {
module.exports = async (serverUrl) => {
// clean cache first if debug
if (coverageOptions.logging === 'debug') {
await new CoverageReport(coverageOptions).clean();
await new CoverageReport(coverageOptions).cleanCache();
}

await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion test/test-v8-esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const generate = async () => {
module.exports = async (serverUrl) => {
// clean cache first if debug
if (coverageOptions.logging === 'debug') {
await new CoverageReport(coverageOptions).clean();
await new CoverageReport(coverageOptions).cleanCache();
}

await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion test/test-v8-minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const generate = async () => {
module.exports = async (serverUrl) => {
// clean cache first if debug
if (coverageOptions.logging === 'debug') {
await new CoverageReport(coverageOptions).clean();
await new CoverageReport(coverageOptions).cleanCache();
}

await Promise.all([
Expand Down
122 changes: 122 additions & 0 deletions test/test-v8-rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const { chromium } = require('playwright');
const EC = require('eight-colors');

const CoverageReport = require('../');

const coverageOptions = {
// logging: 'debug',
reports: [
['v8', {
name: 'My V8 Rollup Coverage Report',
assetsPath: '../assets'
}]
],
outputDir: './docs/v8-rollup'
};

const test1 = async (serverUrl) => {

console.log('start v8-rollup test1 ...');
const browser = await chromium.launch({
// headless: false
});
const page = await browser.newPage();

await Promise.all([
page.coverage.startJSCoverage({
resetOnNavigation: false
}),
page.coverage.startCSSCoverage({
resetOnNavigation: false
})
]);

const url = `${serverUrl}/rollup/`;

console.log(`goto ${url}`);

await page.goto(url);

await new Promise((resolve) => {
setTimeout(resolve, 500);
});

const [jsCoverage, cssCoverage] = await Promise.all([
page.coverage.stopJSCoverage(),
page.coverage.stopCSSCoverage()
]);

const coverageList = [... jsCoverage, ... cssCoverage];

const results = await new CoverageReport(coverageOptions).add(coverageList);
console.log('v8-rollup coverage1 added', results.type);

await browser.close();
};


const test2 = async (serverUrl) => {

console.log('start v8-rollup test2 ...');
const browser = await chromium.launch({
// headless: false
});
const page = await browser.newPage();

await Promise.all([
page.coverage.startJSCoverage({
resetOnNavigation: false
}),
page.coverage.startCSSCoverage({
resetOnNavigation: false
})
]);

const url = `${serverUrl}/rollup/`;

console.log(`goto ${url}`);

await page.goto(url);

await new Promise((resolve) => {
setTimeout(resolve, 500);
});

const [jsCoverage, cssCoverage] = await Promise.all([
page.coverage.stopJSCoverage(),
page.coverage.stopCSSCoverage()
]);

const coverageList = [... jsCoverage, ... cssCoverage];

const results = await new CoverageReport(coverageOptions).add(coverageList);
console.log('v8-rollup coverage2 added', results.type);

await browser.close();
};


const generate = async () => {

console.log('generate v8-rollup coverage reports ...');

const coverageResults = await new CoverageReport(coverageOptions).generate();
console.log('reportPath', EC.magenta(coverageResults.reportPath));

console.log('v8-rollup coverage generated', coverageResults.summary);
};


module.exports = async (serverUrl) => {
// clean cache first if debug
if (coverageOptions.logging === 'debug') {
await new CoverageReport(coverageOptions).cleanCache();
}

await Promise.all([
test1(serverUrl),
test2(serverUrl)
]);

await generate();
};
3 changes: 1 addition & 2 deletions test/test-v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ const generate = async () => {
module.exports = async (serverUrl) => {
// clean cache first if debug
if (coverageOptions.logging === 'debug') {
const coverageReport = new CoverageReport(coverageOptions);
await coverageReport.cleanCache();
await new CoverageReport(coverageOptions).cleanCache();
}

await Promise.all([
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Koa = require('koa');

const testV8 = require('./test-v8.js');
const testV8EsBuild = require('./test-v8-esbuild.js');
const testV8Rollup = require('./test-v8-rollup.js');
const testV8Minify = require('./test-v8-minify.js');

const testIstanbul = require('./test-istanbul.js');
Expand Down Expand Up @@ -98,6 +99,7 @@ const test = async () => {
testIstanbul(serverUrl),
testV8Minify(serverUrl),
testV8EsBuild(serverUrl),
testV8Rollup(serverUrl),
testV8(serverUrl)
]);

Expand Down

0 comments on commit 60cc9b1

Please sign in to comment.