first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

38
node_modules/fetch-s/test/unit/create.spec.js generated vendored Normal file
View File

@ -0,0 +1,38 @@
import fetchMock from 'fetch-mock';
import fetchs from './../../src/fetchs';
describe('创建实例单元测试', () => {
beforeEach(function() {
const headers = {
'Content-Type': 'application/json;charset=utf-8',
'Access-Control-Allow-Origin': '*'
};
const body = { foo: 'bar' };
fetchMock.get('http://www.example.com/api/', {
status: 200,
body,
headers
});
});
afterEach(function() {
fetchMock.restore();
});
it('json', async () => {
const instance = fetchs.create({
origin: 'https://www.example.com'
});
await instance
.get('/api/', {
timeout: 1000
})
.then(r => {
expect(r.data).toEqual({ foo: 'bar' });
})
.catch(e => {
console.dir('error', e);
});
});
});

44
node_modules/fetch-s/test/unit/get.spec.js generated vendored Normal file
View File

@ -0,0 +1,44 @@
import fetchMock from 'fetch-mock';
import fetchs from './../../src/fetchs';
describe('GET单元测试', () => {
beforeEach(function() {
const headers = {
'Content-Type': 'application/json;charset=utf-8',
'Access-Control-Allow-Origin': '*'
};
const body = { foo: 'bar' };
fetchMock.get('http://www.example.com/', {
status: 200,
body,
headers
});
});
afterEach(function() {
fetchMock.restore();
});
it('json', async () => {
await fetchs
.get('http://www.example.com/', {
timeout: 1000
})
.then(r => {
expect(r.data).toEqual({ foo: 'bar' });
})
.catch(e => {
console.dir('error', e);
});
});
it('timeout', async () => {
await fetchs
.get('http://www.example.com/', {
dataType: 'json',
timeout: 0
})
.catch(e => {
expect(e).toEqual(new Error('Request timed out'));
});
});
});

42
node_modules/fetch-s/test/unit/jsonp.spec.js generated vendored Normal file
View File

@ -0,0 +1,42 @@
import jsonp from './../../src/core/jsonp';
// See http://doc.jsfiddle.net/use/echo.html
let url ="http://jsfiddle.net/echo/jsonp/?a=1&b=2";
describe('test jsonp...', () => {
let originalTimeout;
beforeEach(function() {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
afterEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
it('测试正常请求', done => {
jsonp({
url: url,
timeout: 8000,
cache: true
}).then(data => {
expect(data).toEqual({
a: '1',
b: '2'
});
done();
})
});
it('测试超时', done => {
jsonp({
url: url,
timeout: 1,
cache: false
}).catch(e => {
expect(e).toEqual(new Error('Request timed out'));
done();
});
});
});

42
node_modules/fetch-s/test/unit/post.spec.js generated vendored Normal file
View File

@ -0,0 +1,42 @@
import fetchMock from 'fetch-mock';
import fetchs from './../../src/fetchs';
describe('POST单元测试', () => {
beforeEach(function() {
const headers = {
'Content-Type': 'application/json;charset=utf-8',
'Access-Control-Allow-Origin': '*'
};
const body = { foo: 'bar' };
fetchMock.post('http://www.example.com/', {
status: 200,
body,
headers
});
});
afterEach(function() {
fetchMock.restore();
});
it('json', async () => {
await fetchs
.post('http://www.example.com/', {
timeout: 1000
})
.then(r => {
expect(r.data).toEqual({ foo: 'bar' });
});
});
it('timeout', async () => {
await fetchs
.post('http://www.example.com/', {
dataType: 'json',
timeout: 0
})
.catch(e => {
expect(e).toEqual(new Error('Request timed out'));
});
});
});