Skip to content

Commit 6678814

Browse files
committedAug 21, 2019
tooling: Adds use of cypress env variables to handle differing API URL in tests
1 parent 4d3040c commit 6678814

File tree

3 files changed

+99
-93
lines changed

3 files changed

+99
-93
lines changed
 
+74-71
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,124 @@
1-
describe('Integration :: Player Search', () => {
1+
describe("Integration :: Player Search", () => {
2+
const url = Cypress.env("API_URL");
3+
24
beforeEach(() => {
3-
cy.visit('http://localhost:3000')
5+
cy.visit("http://localhost:3000");
46

5-
cy.get('button[data-testid="platform-psn"]').as('psnBtn')
6-
cy.get('button[data-testid="platform-xbl"]').as('xblBtn')
7-
cy.get('button[data-testid="platform-origin"]').as('pcBtn')
7+
cy.get('button[data-testid="platform-psn"]').as("psnBtn");
8+
cy.get('button[data-testid="platform-xbl"]').as("xblBtn");
9+
cy.get('button[data-testid="platform-origin"]').as("pcBtn");
810

9-
cy.get('input[name="player-tag"]').as('playerHandleInput')
11+
cy.get('input[name="player-tag"]').as("playerHandleInput");
1012

11-
cy.get('button[data-testid="submit-btn"]').as('submitBtn')
13+
cy.get('button[data-testid="submit-btn"]').as("submitBtn");
1214

13-
cy.server({ delay: 50 })
14-
})
15+
cy.server({ delay: 50 });
16+
});
1517

16-
it('Should not submit a player search with empty fields', () => {
17-
cy.get('@submitBtn').click()
18+
it("Should not submit a player search with empty fields", () => {
19+
cy.get("@submitBtn").click();
1820

19-
cy.get('.error-msg').contains('Please complete the form')
20-
})
21+
cy.get(".error-msg").contains("Please complete the form");
22+
});
2123

22-
it('Should not submit a player search with only a platform selected', () => {
23-
cy.get('@psnBtn').click()
24+
it("Should not submit a player search with only a platform selected", () => {
25+
cy.get("@psnBtn").click();
2426

25-
cy.get('@submitBtn').click()
27+
cy.get("@submitBtn").click();
2628

27-
cy.get('.error-msg').contains('Please complete the form')
28-
})
29+
cy.get(".error-msg").contains("Please complete the form");
30+
});
2931

30-
it('Should not submit a player search with only a player handle entered', () => {
31-
cy.get('@playerHandleInput').type('leroyjenkins')
32+
it("Should not submit a player search with only a player handle entered", () => {
33+
cy.get("@playerHandleInput").type("leroyjenkins");
3234

33-
cy.get('@submitBtn').click()
35+
cy.get("@submitBtn").click();
3436

35-
cy.get('.error-msg').contains('Please complete the form')
36-
})
37+
cy.get(".error-msg").contains("Please complete the form");
38+
});
3739

38-
it('Should submit a player search for Leroy Jenkins, and display no players found msg', () => {
40+
it("Should submit a player search for Leroy Jenkins, and display no players found msg", () => {
3941
cy.route({
40-
url: 'http://localhost:4000',
41-
method: 'POST',
42+
url,
43+
method: "POST",
4244
response: { data: { searchPlayers: [] } }
43-
}).as('searchLeroyJenkins')
45+
}).as("searchLeroyJenkins");
4446

45-
cy.get('@playerHandleInput').type('leroyjenkins')
47+
cy.get("@playerHandleInput").type("leroyjenkins");
4648

47-
cy.get('@psnBtn').click()
49+
cy.get("@psnBtn").click();
4850

49-
cy.get('@submitBtn').click()
51+
cy.get("@submitBtn").click();
5052

51-
cy.get('@submitBtn').contains('Loading...')
53+
cy.get("@submitBtn").contains("Loading...");
5254

53-
cy.wait('@searchLeroyJenkins')
55+
cy.wait("@searchLeroyJenkins");
5456

55-
cy.get('.error-msg').contains('No players were found with those details')
56-
})
57+
cy.get(".error-msg").contains("No players were found with those details");
58+
});
5759

58-
it('Should submit a player search for DiRTiG, and display results', () => {
59-
cy.fixture('player-search-DiRTiG').then(response => {
60+
it("Should submit a player search for DiRTiG, and display results", () => {
61+
cy.fixture("player-search-DiRTiG").then(response => {
6062
cy.route({
61-
method: 'POST',
63+
method: "POST",
6264
response,
63-
url: 'http://localhost:4000',
64-
}).as('searchDiRTiG')
65-
})
65+
url
66+
}).as("searchDiRTiG");
67+
});
6668

67-
cy.get('@playerHandleInput').type('DiRTiG')
69+
cy.get("@playerHandleInput").type("DiRTiG");
6870

69-
cy.get('@psnBtn').click()
71+
cy.get("@psnBtn").click();
7072

71-
cy.get('@submitBtn').click()
73+
cy.get("@submitBtn").click();
7274

73-
cy.get('@submitBtn').contains('Loading...')
75+
cy.get("@submitBtn").contains("Loading...");
7476

75-
cy.wait('@searchDiRTiG')
77+
cy.wait("@searchDiRTiG");
7678

77-
cy.get('ul[data-testid="search-results"]')
79+
cy.get('ul[data-testid="search-results"]');
7880

7981
cy.get('li[data-testid="psn-dirtig"]')
80-
.find('span[data-testid="user-handle"]').contains('dirtig')
82+
.find('span[data-testid="user-handle"]')
83+
.contains("dirtig");
8184

8285
cy.get('li[data-testid="psn-dirtig"]')
83-
.find('span[data-testid="user-platform"]').contains('psn')
84-
})
86+
.find('span[data-testid="user-platform"]')
87+
.contains("psn");
88+
});
8589

86-
it('Should allow user to click search result and redirect to /stats route', () => {
87-
cy.fixture('player-search-DiRTiG').then(response => {
90+
it("Should allow user to click search result and redirect to /stats route", () => {
91+
cy.fixture("player-search-DiRTiG").then(response => {
8892
cy.route({
89-
method: 'POST',
93+
method: "POST",
9094
response,
91-
url: 'http://localhost:4000',
92-
}).as('searchDiRTiG')
93-
})
95+
url
96+
}).as("searchDiRTiG");
97+
});
9498

95-
cy.get('@playerHandleInput').type('DiRTiG')
99+
cy.get("@playerHandleInput").type("DiRTiG");
96100

97-
cy.get('@psnBtn').click()
101+
cy.get("@psnBtn").click();
98102

99-
cy.get('@submitBtn').click()
103+
cy.get("@submitBtn").click();
100104

101-
cy.get('@submitBtn').contains('Loading...')
105+
cy.get("@submitBtn").contains("Loading...");
102106

103-
cy.wait('@searchDiRTiG')
107+
cy.wait("@searchDiRTiG");
104108

105-
cy.get('ul[data-testid="search-results"]')
109+
cy.get('ul[data-testid="search-results"]');
106110

107111
// THE STACKING OF NETWORK STUBS IS UNPLEASANT, NICER SOLUTION REQUIRED
108-
cy.fixture('player-stats-DiRTiG').then(response => {
112+
cy.fixture("player-stats-DiRTiG").then(response => {
109113
cy.route({
110-
method: 'POST',
114+
method: "POST",
111115
response,
112-
url: 'http://localhost:4000',
113-
}).as('DiRTiGStatsPage')
114-
})
115-
116-
cy.get('li[data-testid="psn-dirtig"]').click()
116+
url
117+
}).as("DiRTiGStatsPage");
118+
});
117119

120+
cy.get('li[data-testid="psn-dirtig"]').click();
118121

119-
cy.wait('@DiRTiGStatsPage')
120-
})
121-
})
122+
cy.wait("@DiRTiGStatsPage");
123+
});
124+
});

‎cypress/support/commands.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
// Set a player session for viewing their stats, due to restrictions on
22
Cypress.Commands.add("setDefaultPlayer", () => {
33
// Setup the network spies
4-
cy.server({ delay: 50 })
4+
cy.server({ delay: 50 });
55

6-
cy.fixture('player-search-DiRTiG').then(response => {
6+
const url = Cypress.env("API_URL");
7+
8+
cy.fixture("player-search-DiRTiG").then(response => {
79
cy.route({
8-
method: 'POST',
10+
method: "POST",
911
response,
10-
url: 'http://localhost:4000',
11-
}).as('searchDiRTiG')
12-
})
12+
url
13+
}).as("searchDiRTiG");
14+
});
1315

14-
cy.visit('http://localhost:3000')
16+
cy.visit("http://localhost:3000");
1517

16-
cy.get('input[name="player-tag"]').type('DiRTiG')
18+
cy.get('input[name="player-tag"]').type("DiRTiG");
1719

18-
cy.get('button[data-testid="platform-psn"]').click()
20+
cy.get('button[data-testid="platform-psn"]').click();
1921

20-
cy.get('button[data-testid="submit-btn"]').click()
22+
cy.get('button[data-testid="submit-btn"]').click();
2123

22-
cy.wait('@searchDiRTiG')
24+
cy.wait("@searchDiRTiG");
2325

24-
cy.fixture('player-stats-DiRTiG').then(response => {
26+
cy.fixture("player-stats-DiRTiG").then(response => {
2527
cy.route({
26-
method: 'POST',
28+
method: "POST",
2729
response,
28-
url: 'http://localhost:4000',
29-
}).as('DiRTiGStatsPage')
30-
})
30+
url
31+
}).as("DiRTiGStatsPage");
32+
});
3133

32-
cy.get('ul[data-testid="search-results"]')
34+
cy.get('ul[data-testid="search-results"]');
3335

34-
cy.get('li[data-testid="psn-dirtig"]').click()
36+
cy.get('li[data-testid="psn-dirtig"]').click();
3537

36-
cy.wait('@DiRTiGStatsPage')
37-
})
38+
cy.wait("@DiRTiGStatsPage");
39+
});

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@
7777
"ci:ping-static": "wait-on http-get://localhost:3000 --delay 10000",
7878
"ci:ping-servers": "npm-run-all --sequential ci:ping-static ci:ping-api",
7979
"ci:lint": "scripts/static-analysis.sh",
80-
"cy:open": "cypress open",
80+
"cy:open": "cypress open --env API_URL=http://localhost:4000",
8181
"cy:verify": "cypress verify",
8282
"ci:serve": "CI_ENV=true now dev",
8383
"build": "webpack --env.production",
84-
"test": "cypress run --record --key f8b075fe-ce9f-4712-ad42-96c913b58cf6"
84+
"test": "cypress run --record --key f8b075fe-ce9f-4712-ad42-96c913b58cf6 --env API_URL=http://localhost:4000/",
85+
"test:ci": "cypress run --record --key f8b075fe-ce9f-4712-ad42-96c913b58cf6 --env API_URL=http://localhost:3000/graphql"
8586
},
8687
"dependencies": {
8788
"apollo-datasource-rest": "^0.6.1",

0 commit comments

Comments
 (0)