Skip to content

Commit 2fa095f

Browse files
authored
infra: try to fix e2e flakyness (#1947)
1 parent 1d4b4b8 commit 2fa095f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

cypress/e2e/api.cy.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,36 @@ describe('API Test', () => {
2323

2424
it('should include at least 1 element in each module', () => {
2525
cy.get('.api-group').each(($el) => {
26-
cy.wrap($el).get('li a[href]').should('have.length.above', 0);
26+
cy.wrap($el).within(() => {
27+
cy.get('li a[href]').should('have.length.above', 0);
28+
});
2729
});
2830
});
2931

3032
it('should not have dead links', () => {
33+
const checked = new Set<string>();
3134
cy.get('.api-group li').each(($el) => {
32-
const text = $el.find('a').text();
33-
const link = $el.find('a').attr('href');
35+
const anchor = $el.find('a');
36+
const text = anchor.text();
37+
const link = anchor.attr('href').split('#')[0];
38+
if (checked.has(link)) {
39+
return;
40+
}
3441

35-
cy.request(`/api/${link}`).should((response) => {
36-
expect(response.status).to.eq(200);
37-
expect(response.body).to.include(text);
38-
expect(response.body).to.not.include('PAGE NOT FOUND');
39-
});
42+
checked.add(link);
43+
44+
cy.request({
45+
method: 'HEAD',
46+
url: `/api/${link}`,
47+
failOnStatusCode: false,
48+
})
49+
.should(({ status }) => {
50+
expect(
51+
status,
52+
`${text} to have a working link: /api/${link}`
53+
).to.eq(200);
54+
})
55+
.end();
4056
});
4157
});
4258
});

0 commit comments

Comments
 (0)