-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6010f5e
commit 7d1081e
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ''; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.