-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
should log concurrent requests (closes #7977)
- Loading branch information
1 parent
2058322
commit c816af2
Showing
6 changed files
with
89 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
test/functional/fixtures/regression/gh-7977/pages/index.html
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,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>gh-7977</title> | ||
</head> | ||
<body> | ||
<button>click me</button> | ||
<script> | ||
function handler () { | ||
for (let i = 0; i < 100; i++) { | ||
fetch('http://localhost:3000/api/data'); | ||
} | ||
} | ||
|
||
document.querySelector('button').addEventListener('click', handler); | ||
</script> | ||
</body> | ||
</html> |
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 @@ | ||
const createTestCafe = require('../../../../../lib'); | ||
const { onlyInNativeAutomation } = require('../../../utils/skip-in'); | ||
const path = require('path'); | ||
const expect = require('chai').expect; | ||
|
||
const EXPECTED_REQUEST_COUNT = 300; | ||
|
||
let testcafe = null; | ||
|
||
describe('[Regression](GH-7977)', function () { | ||
onlyInNativeAutomation('Should log all concurrent requests', function () { | ||
return createTestCafe('127.0.0.1', 1335, 1336) | ||
.then(tc => { | ||
testcafe = tc; | ||
}) | ||
.then(() => { | ||
return testcafe.createRunner() | ||
.browsers(`chrome:headless`) | ||
.concurrency(3) | ||
.src(path.join(__dirname, './testcafe-fixtures/index.js')) | ||
.run(); | ||
}) | ||
.then(() => { | ||
return testcafe.close(); | ||
}) | ||
.then(() => { | ||
expect(require('./testcafe-fixtures/requestCounter').get()).eql(EXPECTED_REQUEST_COUNT); | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
test/functional/fixtures/regression/gh-7977/testcafe-fixtures/index.js
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 { RequestLogger } from 'testcafe'; | ||
|
||
const logger = new RequestLogger(/api\/data/, { | ||
logResponseBody: true, | ||
logRequestHeaders: true, | ||
stringifyResponseBody: true, | ||
}); | ||
|
||
fixture `Concurrent request loggers` | ||
.page `http://localhost:3000/fixtures/regression/gh-7977/pages/index.html` | ||
.requestHooks(logger); | ||
|
||
for (let i = 0; i < 3; i++) { | ||
test(`send multiple requests - ${i}`, async t => { | ||
await t.click('button'); | ||
|
||
require('./requestCounter').add(logger.requests.filter(r => !!r.response.body).length); | ||
}); | ||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
test/functional/fixtures/regression/gh-7977/testcafe-fixtures/requestCounter.js
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,12 @@ | ||
let count = 0; | ||
|
||
const requestCounter = { | ||
add (value) { | ||
count += value; | ||
}, | ||
get () { | ||
return count; | ||
}, | ||
}; | ||
|
||
module.exports = requestCounter; |