-
Notifications
You must be signed in to change notification settings - Fork 2k
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
58e693f
commit 975bb6d
Showing
1 changed file
with
19 additions
and
3 deletions.
There are no files selected for viewing
22 changes: 19 additions & 3 deletions
22
packages/shared/src/assets-transpilers/__tests__/script.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 |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import { expect, it } from 'vitest'; | ||
import transpileScript from '../script'; | ||
import { StandardSandbox } from '../../../../sandbox/src/core/sandbox/StandardSandbox'; | ||
|
||
it('inline script not include sourceURL', () => { | ||
class MockSandbox { | ||
id = 'testApp'; | ||
constantIntrinsicNames = []; | ||
makeEvaluateFactory(source: string, sourceURL?: string): string { | ||
const sourceMapURL = sourceURL ? `//# sourceURL=${sourceURL}\n` : ''; | ||
const globalObjectOptimizer = this.constantIntrinsicNames.length | ||
? `const {${this.constantIntrinsicNames.join(',')}} = this;` | ||
: ''; | ||
// eslint-disable-next-line max-len | ||
return `;(function(){with(this){${globalObjectOptimizer}${source}\n${sourceMapURL}}}).bind(window.${this.id})();`; | ||
} | ||
} | ||
|
||
const scriptElement = document.createElement('script'); | ||
scriptElement.innerHTML = 'console.log("hello world")'; | ||
const sandboxInstance = new StandardSandbox("app", {}); | ||
const sandboxInstance = new MockSandbox(); | ||
const publicPath = 'http://localhost:8000'; | ||
const transpiledScriptElement = transpileScript(scriptElement, publicPath, {fetch: window.fetch, rawNode: scriptElement, sandbox: sandboxInstance}); | ||
const transpiledScriptElement = transpileScript(scriptElement, publicPath, { | ||
fetch: window.fetch, | ||
rawNode: scriptElement, | ||
sandbox: sandboxInstance, | ||
}); | ||
expect(transpiledScriptElement.innerHTML).toEqual(expect.not.stringContaining(`//# sourceURL=${publicPath}`)); | ||
}); |