Skip to content

Commit

Permalink
feat: add e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jan 26, 2024
1 parent 6010f5e commit 7d1081e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
50 changes: 50 additions & 0 deletions e2e/cases/rsdoctor/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'node:path';
import { expect } from '@playwright/test';
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { fse } from '@rsbuild/shared';

const packagePath = path.join(
__dirname,
'node_modules/@rsdoctor/rspack-plugin',
);
const testFile = path.join(packagePath, 'test.txt');

rspackOnlyTest(
'should register Rsdoctor plugin when process.env.RSDOCTOR is true',
async () => {
fse.removeSync(packagePath);
fse.copySync(path.join(__dirname, 'mock'), packagePath);

const { logs, restore } = proxyConsole();
process.env.RSDOCTOR = 'true';

await build({
cwd: __dirname,
});

expect(fse.existsSync(testFile)).toBe(true);
expect(
logs.some((log) => log.includes('@rsdoctor') && log.includes('enabled')),
).toBe(true);

process.env.RSDOCTOR = '';
restore();
},
);

rspackOnlyTest(
'should not register Rsdoctor plugin when process.env.RSDOCTOR is false',
async () => {
fse.removeSync(packagePath);
fse.copySync(path.join(__dirname, 'mock'), packagePath);

process.env.RSDOCTOR = 'false';

await build({
cwd: __dirname,
});

expect(fse.existsSync(testFile)).toBe(false);
process.env.RSDOCTOR = '';
},
);
14 changes: 14 additions & 0 deletions e2e/cases/rsdoctor/mock/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('node:path');
const { fse } = require('@rsbuild/shared');

class RsdoctorRspackPlugin {
name = 'RsdoctorRspackPlugin';

apply(compiler) {
compiler.hooks.done.tap('rsdoctor:test', () => {
fse.outputFileSync(path.join(__dirname, './test.txt'), 'test');
});
}
}

module.exports.RsdoctorRspackPlugin = RsdoctorRspackPlugin;
6 changes: 6 additions & 0 deletions e2e/cases/rsdoctor/mock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@rsdoctor/rspack-plugin",
"private": true,
"version": "1.0.0",
"main": "index.cjs"
}
1 change: 1 addition & 0 deletions e2e/cases/rsdoctor/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d1081e

Please sign in to comment.