Skip to content

Commit 92d0e0a

Browse files
committed
add download API test
1 parent 7fe2361 commit 92d0e0a

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/test/suite/download.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import assert = require("assert");
2+
import { downloadFromMultiSources } from "../../utils/downloadFile";
3+
4+
suite("test download", async function () {
5+
test("test download with fetch", async function () {
6+
const list = [
7+
'https://cdn.jsdelivr.net/gh/MicrosoftDocs/cpp-docs@master/docs/assembler/masm/assume.md',
8+
'https://raw.githubusercontent.com/MicrosoftDocs/cpp-docs/master/docs/assembler/masm/assume.md',
9+
'https://gitee.com/dosasm/cpp-docs/raw/master/docs/assembler/masm/assume.md'
10+
];
11+
for (const url of list) {
12+
const str = await downloadFromMultiSources([url]);
13+
assert.ok(str, url);
14+
}
15+
});
16+
});

src/test/suite/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function run(): Promise<void> {
2323
const testsRoot = path.resolve(__dirname, '..');
2424

2525
return new Promise((c, e) => {
26-
glob('**/*.test.js', { cwd: testsRoot }, (err, files) => {
26+
glob('**/download.test.js', { cwd: testsRoot }, (err, files) => {
2727
if (err) {
2828
return e(err);
2929
}

src/utils/downloadFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* API for downloading information from web
33
*/
44
import { logger } from "./logger";
5+
import fetch from "node-fetch";
56

67
export async function downloadFromMultiSources(urls: string[]): Promise<string | undefined> {
78
for (const url of urls) {

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const config = {
4949
},
5050
plugins: [
5151
new webpack.ProvidePlugin({
52-
fetch: 'node-fetch',
52+
// fetch: 'node-fetch',
5353
}),
5454
],
5555
optimization: {
@@ -105,6 +105,7 @@ const webExtensionConfig = {
105105
],
106106
externals: {
107107
vscode: 'commonjs vscode', // ignored because it doesn't exist
108+
'node-fetch':'window fetch'
108109
},
109110
performance: {
110111
hints: false,

0 commit comments

Comments
 (0)