generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
101 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const { defineConfig } = require("cypress"); | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
}) |
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 @@ | ||
// eslint-disable-next-line no-undef | ||
describe('HTTPRequest', () => { | ||
// eslint-disable-next-line no-undef | ||
it('GET Call', () => { | ||
// eslint-disable-next-line no-unused-expressions, no-undef | ||
cy.request( | ||
'GET', | ||
'https://001f08b9-acb7-4c3a-a54f-a9254b7e8e55.mock.pstmn.io/get?msg=hello' | ||
) | ||
.its('status') | ||
.should('equal', 200) | ||
}) | ||
}) |
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,30 @@ | ||
// eslint-disable-next-line no-undef | ||
describe('E2E Tests to MockAPI', () => { | ||
// eslint-disable-next-line no-undef | ||
beforeEach(() => { | ||
// 跑E2E測試時,intercept時會攔截XHR、fetch、跨域請求,將get方法呼叫的API改為放在fixtures資料夾的hello.json* | ||
// eslint-disable-next-line no-undef | ||
cy.intercept( | ||
'GET', | ||
'https://001f08b9-acb7-4c3a-a54f-a9254b7e8e55.mock.pstmn.io/get?msg=hello', | ||
{ | ||
fixture: 'hello.json' | ||
} | ||
).as('getAPI') | ||
}) | ||
|
||
// eslint-disable-next-line no-undef | ||
it('should load data from Local Mock API', () => { | ||
// eslint-disable-next-line no-undef | ||
cy.visit('http://localhost:3001/') | ||
|
||
// eslint-disable-next-line no-undef | ||
cy.wait('@getAPI', { timeout: 10000 }) | ||
.its('response.body') | ||
.then((data) => { | ||
// 在這裡設定預期從API獲取到的數據 | ||
// eslint-disable-next-line no-undef | ||
expect(data.args.msg).to.equal('hello') | ||
}) | ||
}) | ||
}) |
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,18 @@ | ||
{ | ||
"args": { | ||
"msg": "hello" | ||
}, | ||
"headers": { | ||
"x-forwarded-proto": "https", | ||
"x-forwarded-port": "443", | ||
"host": "postman-echo.com", | ||
"x-amzn-trace-id": "Root=1-64ac06fd-778a564925e76121259dd571", | ||
"x-api-key": "PMAK-64a766dd07cb240031aee0fa-a5ac0a936c61951cec0d9a531788926d41", | ||
"user-agent": "PostmanRuntime/7.32.3", | ||
"accept": "*/*", | ||
"cache-control": "no-cache", | ||
"postman-token": "c462399d-5328-4c40-be44-c9f6ab7fdf4b", | ||
"accept-encoding": "gzip, deflate, br" | ||
}, | ||
"url": "https://postman-echo.com/get?msg=hello" | ||
} |
Binary file removed
BIN
-30.6 KB
...ss/screenshots/spec.cy.js/My First Test -- Visits the Kitchen Sink (failed).png
Binary file not shown.
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
Binary file not shown.
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,21 @@ | ||
import { useEffect, useState } from 'react' | ||
import axios from 'axios' | ||
|
||
function getAPI() { | ||
const [data, setData] = useState({}) | ||
useEffect(() => { | ||
axios({ | ||
method: 'GET', | ||
url: 'https://001f08b9-acb7-4c3a-a54f-a9254b7e8e55.mock.pstmn.io/get?msg=hello' | ||
}) | ||
.then((res) => { | ||
setData(res.data.args) | ||
}) | ||
.catch((error) => { | ||
console.log(error) | ||
}) | ||
}, []) | ||
return { data } | ||
} | ||
|
||
export default getAPI |
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,5 +1,11 @@ | ||
import getAPI from '../api/getAPI' | ||
|
||
const App = () => { | ||
return <div>Hello World!</div> | ||
const { data } = getAPI() | ||
return ( | ||
<> | ||
<div>title:{data.msg}</div> | ||
</> | ||
) | ||
} | ||
|
||
export default App |