-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e case for conditional exports
- Loading branch information
Showing
13 changed files
with
89 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
const URL_PREFIX = Cypress.env('E2E_BASE').replace(/\/$/, '') | ||
|
||
// override the default cy.visit command to prepend base | ||
// @ts-expect-error: could not type this method correctly | ||
Cypress.Commands.overwrite('visit', (originalFn, url, options) => | ||
// @ts-expect-error: could not type this method correctly | ||
originalFn(`${URL_PREFIX}${url}`, options), | ||
Cypress.Commands.overwrite('visit', (originalFn, ...args) => { | ||
// cy.visit(url, options) | ||
if (typeof args[0] === 'string') { | ||
// @ts-expect-error: could not type this correctly | ||
return originalFn(`${URL_PREFIX}${args[0]}`, args[1]) | ||
} | ||
|
||
// cy.visit(options) | ||
return originalFn({ | ||
...args[0], | ||
url: `${URL_PREFIX}${args[0].url}`, | ||
}) | ||
}) | ||
|
||
// add a custom request command to prepend base | ||
Cypress.Commands.add('requestWithBase', (url, options) => | ||
cy.request(`${URL_PREFIX}${url}`, options), | ||
) | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
requestWithBase: <T = any>( | ||
url: string, | ||
options?: Partial<Cypress.RequestOptions>, | ||
) => Chainable<Cypress.Response<T>> | ||
} | ||
} | ||
} | ||
|
||
export {} |
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,5 @@ | ||
<script setup> | ||
import str from '@vuepress-e2e/conditional-exports' | ||
</script> | ||
|
||
{{ str }} |
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 @@ | ||
export default 'browser-mjs' |
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 @@ | ||
module.exports = 'node-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 @@ | ||
export default 'node-mjs' |
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,19 @@ | ||
{ | ||
"name": "@vuepress-e2e/conditional-exports", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./types.d.ts", | ||
"browser": "./browser.mjs", | ||
"node": "./node.mjs", | ||
"module": "./node.mjs", | ||
"import": "./node.mjs", | ||
"require": "./node.cjs", | ||
"default": "./node.cjs" | ||
}, | ||
"./*": "./*" | ||
}, | ||
"main": "cjs.js", | ||
"module": "esm.js", | ||
"types": "types.d.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,2 @@ | ||
declare const str: string | ||
export default str |
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,13 @@ | ||
it('should support visiting non-ASCII paths directly', () => { | ||
const E2E_COMMAND = Cypress.env('E2E_COMMAND') | ||
|
||
cy.visit('/imports/conditional-exports.html') | ||
|
||
cy.get('.e2e-theme-content p').should('have.text', 'browser-mjs') | ||
|
||
if (E2E_COMMAND === 'build') { | ||
cy.requestWithBase('/imports/conditional-exports.html') | ||
.its('body') | ||
.should('include', '<p>node-mjs</p>') | ||
} | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.