Skip to content

Commit

Permalink
test: cover the case with the request issued by cy.request()
Browse files Browse the repository at this point in the history
relates-to #59
  • Loading branch information
derevnjuk committed Feb 7, 2023
1 parent d1b6f6b commit e106cf0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions cypress/e2e/record-har.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ describe('Record HAR', () => {
});
});

// ADHOC: cy.request() sends requests to actual endpoints, bypassing the interceptor
// For details please refer to the documentation at
// https://docs.cypress.io/api/commands/request#cyrequest-sends-requests-to-actual-endpoints-bypassing-those-defined-using-cyintercept
it.skip('records a request made by Cypress (not the tested app)', () => {
cy.recordHar();

cy.request('/api/products');

cy.saveHar({ waitForIdle: true });

cy.findHar()
.its('log.entries')
.should('contain.something.like', {
request: {
url: /\/api\/products$/
}
});
});

// ADHOC: .mjs files are excluded as Cypress forces ts-node to use the 'commonjs' module format. Covered by unit tests.
// For details please refer to https://github.com/cypress-io/cypress/blob/e6b2466f7b219a86da46c1ac720432ef75193ca4/packages/server/lib/plugins/child/ts_node.js#L25
['.js', '.ts', '.cjs'].forEach(ext =>
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ like.extend({
Cypress.Commands.add('findHar', (fileName?: string) =>
cy
.readFile(fileName ?? Cypress.spec.name.replace('.ts', '.har'))
.then(data => cy.wrap<Har>(JSON.parse(data)))
.then(data => cy.wrap<Har>(data ? JSON.parse(data) : undefined))
);

// check a file/folder existence
Expand Down

0 comments on commit e106cf0

Please sign in to comment.