-window.MOCKS = {
+export default {
master: [
{
sha: 'd1527fbee422c7170e56845e55b49c4fd6de72a7',
import path from 'path'
import { setupPuppeteer } from './e2eUtils'
+import mocks from './commits.mock'
describe('e2e: commits', () => {
const { page, click, count, text, isChecked } = setupPuppeteer()
async function testCommits(apiType: 'classic' | 'composition') {
const baseUrl = `file://${path.resolve(
__dirname,
- `../${apiType}/commits.html#test`
+ `../${apiType}/commits.html`
)}`
+ // intercept and mock the response to avoid hitting the actual API
+ await page().setRequestInterception(true)
+ page().on('request', req => {
+ const match = req.url().match(/&sha=(.*)$/)
+ if (!match) {
+ req.continue()
+ } else {
+ req.respond({
+ status: 200,
+ contentType: 'application/json',
+ headers: { 'Access-Control-Allow-Origin': '*' },
+ body: JSON.stringify(mocks[match[1] as 'master' | 'sync'])
+ })
+ }
+ })
+
await page().goto(baseUrl)
await page().waitFor('li')
expect(await count('input')).toBe(2)
beforeEach(async () => {
browser = await puppeteer.launch(puppeteerOptions)
page = await browser.newPage()
+
+ page.on('console', e => {
+ if (e.type() === 'error') {
+ console.error(`Error from Puppeteer-loaded page:`, e)
+ }
+ })
})
afterEach(async () => {
<script src="../../dist/vue.global.js"></script>
-<script src="../mocks/commits.js"></script>
<div id="demo">
<h1>Latest Vue.js Commits</h1>
methods: {
fetchData() {
- if (window.location.hash === '#test') {
- // use mocks in e2e to avoid dependency on network / authentication
- setTimeout(() => {
- this.commits = window.MOCKS[this.currentBranch]
- }, 0)
- } else {
- fetch(`${API_URL}${this.currentBranch}`)
- .then(res => res.json())
- .then(data => {
- this.commits = data
- })
- }
+ fetch(`${API_URL}${this.currentBranch}`)
+ .then(res => res.json())
+ .then(data => {
+ this.commits = data
+ })
},
truncate(v) {
const newline = v.indexOf('\n')
<script src="../../dist/vue.global.js"></script>
-<script src="../mocks/commits.js"></script>
<div id="demo">
<h1>Latest Vue.js Commits</h1>
const currentBranch = ref('master')
const commits = ref(null)
- watch([currentBranch, commits], () => {
- if (window.location.hash === '#test') {
- // use mocks in e2e to avoid dependency on network / authentication
- setTimeout(() => {
- commits.value = window.MOCKS[currentBranch.value]
- }, 0)
- } else {
- fetch(`${API_URL}${currentBranch.value}`)
- .then(res => res.json())
- .then(data => { commits.value = data })
- }
+ watch(() => {
+ fetch(`${API_URL}${currentBranch.value}`)
+ .then(res => res.json())
+ .then(data => {
+ console.log(data)
+ commits.value = data
+ })
})
return {