Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: patak-dev <matias.capeletto@gmail.com>
- Loading branch information
Showing
6 changed files
with
57 additions
and
43 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
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
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,39 @@ | ||
import { definePlugin } from '../../plugins/define' | ||
import { resolveConfig } from '../../config' | ||
|
||
async function createDefinePluginTransform( | ||
define: Record<string, any> = {}, | ||
build = true, | ||
ssr = false | ||
) { | ||
const config = await resolveConfig({ define }, build ? 'build' : 'serve') | ||
const instance = definePlugin(config) | ||
return async (code: string) => { | ||
const result = await instance.transform.call({}, code, 'foo.ts', { ssr }) | ||
return result?.code || result | ||
} | ||
} | ||
|
||
describe('definePlugin', () => { | ||
test('replaces custom define', async () => { | ||
const transform = await createDefinePluginTransform({ | ||
__APP_VERSION__: JSON.stringify('1.0') | ||
}) | ||
expect(await transform('const version = __APP_VERSION__ ;')).toBe( | ||
'const version = "1.0" ;' | ||
) | ||
expect(await transform('const version = __APP_VERSION__;')).toBe( | ||
'const version = "1.0";' | ||
) | ||
}) | ||
|
||
test('replaces import.meta.env.SSR with false', async () => { | ||
const transform = await createDefinePluginTransform() | ||
expect(await transform('const isSSR = import.meta.env.SSR ;')).toBe( | ||
'const isSSR = false ;' | ||
) | ||
expect(await transform('const isSSR = import.meta.env.SSR;')).toBe( | ||
'const isSSR = false;' | ||
) | ||
}) | ||
}) |
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