-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
165 additions
and
13 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
v22 |
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,33 @@ | ||
const assert = require('node:assert'); | ||
// eslint-disable-next-line import/no-unresolved | ||
const { newServer } = require('mock-xmlhttprequest'); | ||
|
||
function functionToTest() { | ||
return new Promise((resolve, reject) => { | ||
// eslint-disable-next-line no-undef | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', '/my/url'); | ||
xhr.onload = () => resolve(JSON.parse(xhr.response)); | ||
xhr.onerror = () => reject(xhr.statusText); | ||
xhr.send(); | ||
}); | ||
} | ||
|
||
const server = newServer({ | ||
get: ['/my/url', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: '{ "message": "Success!" }', | ||
}], | ||
}); | ||
|
||
async function integrationTest() { | ||
try { | ||
server.install(); | ||
const result = await functionToTest(); | ||
assert.strictEqual(result.message, 'Success!'); | ||
} finally { | ||
server.remove(); | ||
} | ||
} | ||
|
||
integrationTest(); |
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,11 @@ | ||
{ | ||
"name": "mock-xmlhttprequest-integration-test-esm", | ||
"description": "Integration test for XMLHttpRequest in a Node.js commonjs project", | ||
"type": "commonjs", | ||
"scripts": { | ||
"test": "node index.js" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
} | ||
} |
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,33 @@ | ||
import assert from 'node:assert'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { newServer } from 'mock-xmlhttprequest'; | ||
|
||
function functionToTest() { | ||
return new Promise((resolve, reject) => { | ||
// eslint-disable-next-line no-undef | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', '/my/url'); | ||
xhr.onload = () => resolve(JSON.parse(xhr.response)); | ||
xhr.onerror = () => reject(xhr.statusText); | ||
xhr.send(); | ||
}); | ||
} | ||
|
||
const server = newServer({ | ||
get: ['/my/url', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: '{ "message": "Success!" }', | ||
}], | ||
}); | ||
|
||
async function integrationTest() { | ||
try { | ||
server.install(); | ||
const result = await functionToTest(); | ||
assert.strictEqual(result.message, 'Success!'); | ||
} finally { | ||
server.remove(); | ||
} | ||
} | ||
|
||
integrationTest(); |
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,11 @@ | ||
{ | ||
"name": "mock-xmlhttprequest-integration-test-esm", | ||
"description": "Integration test for XMLHttpRequest in a Node.js module project", | ||
"type": "module", | ||
"scripts": { | ||
"test": "node index.js" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
} | ||
} |
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