-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: banner plugin switch condition (#721)
- Loading branch information
Showing
5 changed files
with
130 additions
and
7 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
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
123 changes: 123 additions & 0 deletions
123
e2e/cases/doctor-rspack/tag-plugin-without-banner.test.ts
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,123 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { getSDK, setSDK } from '@rsdoctor/core/plugins'; | ||
import { compileByRspack } from '@scripts/test-helper'; | ||
import { Utils } from '@rsdoctor/core/build-utils'; | ||
import { Compiler } from '@rspack/core'; | ||
import path from 'path'; | ||
import { createRsdoctorPlugin } from './test-utils'; | ||
|
||
let reportLoaderStartOrEndTimes = 0; | ||
|
||
async function rspackCompile( | ||
_tapName: string, | ||
compile: typeof compileByRspack, | ||
) { | ||
const file = path.resolve(__dirname, './fixtures/a.js'); | ||
const loader = path.resolve(__dirname, './fixtures/loaders/comment.js'); | ||
|
||
const esmLoader = path.resolve( | ||
__dirname, | ||
'./fixtures/loaders/esm-serialize-query-to-comment.mjs', | ||
); | ||
|
||
const res = await compile(file, { | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
output: { | ||
path: path.join(__dirname, '../doctor-rspack/dist'), | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js/, | ||
use: loader, | ||
}, | ||
{ | ||
test: /\.js/, | ||
use: esmLoader, | ||
}, | ||
{ | ||
test: /\.[jt]s$/, | ||
use: { | ||
loader: 'builtin:swc-loader', | ||
options: { | ||
sourceMap: true, | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
}, | ||
externalHelpers: true, | ||
preserveAllComments: false, | ||
}, | ||
}, | ||
}, | ||
type: 'javascript/auto', | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
// @ts-ignore | ||
createRsdoctorPlugin({ | ||
supports: { | ||
banner: true, | ||
}, | ||
}), | ||
{ | ||
name: 'Foo', | ||
apply(compiler: Compiler) { | ||
compiler.hooks.beforeRun.tapPromise( | ||
{ name: 'Foo', stage: 99999 }, | ||
async () => { | ||
const sdk = getSDK(); | ||
setSDK( | ||
new Proxy(sdk, { | ||
get(target, key, receiver) { | ||
switch (key) { | ||
case 'reportLoader': | ||
return null; | ||
case 'reportLoaderStartOrEnd': | ||
return (_data: any) => { | ||
reportLoaderStartOrEndTimes += 1; | ||
}; | ||
default: | ||
return Reflect.get(target, key, receiver); | ||
} | ||
}, | ||
set(target, key, value, receiver) { | ||
return Reflect.set(target, key, value, receiver); | ||
}, | ||
defineProperty(target, p, attrs) { | ||
return Reflect.defineProperty(target, p, attrs); | ||
}, | ||
}), | ||
); | ||
}, | ||
); | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
return res; | ||
} | ||
|
||
test('rspack banner plugin', async () => { | ||
const tapName = 'Foo'; | ||
await rspackCompile(tapName, compileByRspack); | ||
const sdk = getSDK(); | ||
|
||
// @ts-ignore | ||
const bundle = Utils.parseBundle( | ||
path.join(__dirname, './fixtures/rspack-banner-plugin.js'), | ||
// @ts-ignore | ||
sdk.getStoreData().moduleGraph.modules, | ||
); | ||
|
||
expect(JSON.stringify(bundle.modules)).toBe( | ||
'{"":{"size":313,"sizeConvert":"313 B","content":"function (\\n __unused_webpack_module,\\n __webpack_exports__,\\n __webpack_require__,\\n ) {\\n \'use strict\';\\n __webpack_require__.r(__webpack_exports__);\\n __webpack_require__.d(__webpack_exports__, {\\n a: function () {\\n return a;\\n },\\n });\\n var a = 1;\\n }"}}', | ||
); | ||
const res = sdk.getStoreData().chunkGraph; | ||
expect(res.assets[0].content).toContain('RSDOCTOR_START'); | ||
expect(res.assets[0].content).toContain('RSDOCTOR_END'); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.