Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update define expression #7517

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/playground/define/__tests__/define.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
test('string', async () => {
const defines = require('../vite.config.js').define

expect(await page.textContent('.exp')).toBe(String(eval(defines.__EXP__)))
expect(await page.textContent('.exp')).toBe(
String(typeof eval(defines.__EXP__))
)
expect(await page.textContent('.string')).toBe(JSON.parse(defines.__STRING__))
expect(await page.textContent('.number')).toBe(String(defines.__NUMBER__))
expect(await page.textContent('.boolean')).toBe(String(defines.__BOOLEAN__))
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/define/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>Define</h1>

<script type="module">
const __VAR_NAME__ = true // ensure define doesn't replace var name
text('.exp', __EXP__)
text('.exp', typeof __EXP__) // typeof __EXP__ would be `boolean` instead of `string`
text('.string', __STRING__)
text('.number', __NUMBER__)
text('.boolean', __BOOLEAN__)
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/define/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
define: {
__EXP__: '1 + 1',
__EXP__: 'false',
__STRING__: '"hello"',
__NUMBER__: 123,
__BOOLEAN__: true,
Expand Down