Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/typescript tests #5375

Merged
merged 4 commits into from Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Expand Up @@ -3,10 +3,9 @@
.tscache
.DS_Store
node_modules/
typings/
coverage/
test/typescript/axios.js*
sauce_connect.log
test/module/cjs/node_modules/
test/module/cjs/package-lock.json
test/module/**/package-lock.json
backup/
./.husky/
32 changes: 20 additions & 12 deletions index.d.cts
Expand Up @@ -18,16 +18,9 @@ type AxiosHeaderGetter = ((parser?: RegExp) => RegExpExecArray | null) |

type AxiosHeaderTester = (matcher?: AxiosHeaderMatcher) => boolean;

type MaxUploadRate = number;

type MaxDownloadRate = number;

type Milliseconds = number;

declare class AxiosHeaders {
constructor(
headers?: RawAxiosHeaders | AxiosHeaders,
defaultHeaders?: RawAxiosHeaders | AxiosHeaders
headers?: RawAxiosHeaders | AxiosHeaders
);

set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
Expand All @@ -44,12 +37,16 @@ declare class AxiosHeaders {

normalize(format: boolean): AxiosHeaders;

concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string>): AxiosHeaders;

toJSON(asStrings?: boolean): RawAxiosHeaders;

static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;

static accessor(header: string | string[]): AxiosHeaders;

static concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string>): AxiosHeaders;

setContentType: AxiosHeaderSetter;
getContentType: AxiosHeaderGetter;
hasContentType: AxiosHeaderTester;
Expand Down Expand Up @@ -199,7 +196,7 @@ declare namespace axios {

type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>;

type AxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders> & AxiosHeaders;
type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;

type RawAxiosResponseHeaders = Partial<Record<string, string> & {
"set-cookie"?: string[]
Expand Down Expand Up @@ -321,6 +318,10 @@ declare namespace axios {
serialize?: CustomParamsSerializer;
}

type MaxUploadRate = number;

type MaxDownloadRate = number;

type BrowserProgressEvent = any;

interface AxiosProgressEvent {
Expand All @@ -335,20 +336,26 @@ declare namespace axios {
event?: BrowserProgressEvent;
}

type Milliseconds = number;

type AxiosAdapterName = 'xhr' | 'http' | string;

type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;

interface AxiosRequestConfig<D = any> {
url?: string;
method?: Method | string;
baseURL?: string;
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
headers?: RawAxiosRequestHeaders;
headers?: RawAxiosRequestHeaders | AxiosHeaders;
params?: any;
paramsSerializer?: ParamsSerializerOptions;
data?: D;
timeout?: Milliseconds;
timeoutErrorMessage?: string;
withCredentials?: boolean;
adapter?: AxiosAdapter;
adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
auth?: AxiosBasicCredentials;
responseType?: ResponseType;
responseEncoding?: responseEncoding | string;
Expand Down Expand Up @@ -396,7 +403,7 @@ declare namespace axios {
}

interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
headers?: RawAxiosRequestHeaders | Partial<HeadersDefaults>;
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
}

interface AxiosResponse<T = any, D = any> {
Expand Down Expand Up @@ -485,6 +492,7 @@ declare namespace axios {
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
AxiosHeaders: typeof AxiosHeaders;
}
}

Expand Down
7 changes: 4 additions & 3 deletions index.d.ts
Expand Up @@ -71,7 +71,7 @@ export class AxiosHeaders {

export type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>;

export type AxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders> & AxiosHeaders;
export type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;

export type RawAxiosResponseHeaders = Partial<Record<string, string> & {
"set-cookie"?: string[]
Expand Down Expand Up @@ -289,7 +289,7 @@ export interface AxiosRequestConfig<D = any> {
baseURL?: string;
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
headers?: RawAxiosRequestHeaders;
headers?: RawAxiosRequestHeaders | AxiosHeaders;
params?: any;
paramsSerializer?: ParamsSerializerOptions;
data?: D;
Expand Down Expand Up @@ -344,7 +344,7 @@ export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'hea
}

export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
headers?: RawAxiosRequestHeaders | Partial<HeadersDefaults>;
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
}

export interface AxiosResponse<T = any, D = any> {
Expand Down Expand Up @@ -499,6 +499,7 @@ export interface AxiosStatic extends AxiosInstance {
CancelToken: CancelTokenStatic;
Axios: typeof Axios;
AxiosError: typeof AxiosError;
HttpStatusCode: typeof HttpStatusCode;
readonly VERSION: string;
isCancel: typeof isCancel;
all: typeof all;
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -23,7 +23,7 @@
"type": "module",
"types": "index.d.ts",
"scripts": {
"test": "npm run test:eslint && npm run test:mocha && npm run test:karma && npm run test:exports && npm run test:dtslint",
"test": "npm run test:eslint && npm run test:mocha && npm run test:karma && npm run test:dtslint && npm run test:exports",
"test:eslint": "node bin/ssl_hotfix.js eslint lib/**/*.js",
"test:dtslint": "node bin/ssl_hotfix.js dtslint",
"test:mocha": "node bin/ssl_hotfix.js mocha test/unit/**/*.js --timeout 30000 --exit",
Expand All @@ -42,9 +42,11 @@
"fix": "eslint --fix lib/**/*.js",
"prepare": "husky install && npm run prepare:hooks",
"prepare:hooks": "npx husky add .husky/commit-msg \"npx commitlint --edit $1\"",
"release:dry": "release-it --dry-run",
"release:dry": "release-it --dry-run --no-npm",
"release:info": "release-it --release-version",
"prerelease:no-npm": "release-it --preRelease=beta --no-npm",
"prerelease": "release-it --preRelease=beta",
"release:no-npm": "release-it --no-npm",
"release": "release-it"
},
"repository": {
Expand Down
46 changes: 46 additions & 0 deletions test/module/test.js
Expand Up @@ -14,6 +14,16 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));

const exec = util.promisify(cp.exec);

const spawn = (command, args) => new Promise((resolve, reject) => {
cp.spawn(command, args, {
shell : true,
stdio: 'inherit'
}).once('error', reject).on(
'close',
(code) => code ? reject(new Error(`Exit code ${code}`)) : resolve()
);
});

const {Axios} = axiosFactory;

const ignoreList = ['default'];
Expand Down Expand Up @@ -134,4 +144,40 @@ describe('module', function () {
await exec(`npm test --prefix ${pkgPath}`, {});
});
});

describe('typings', () => {
describe('ESM', ()=> {
const pkgPath = path.join(__dirname, './typings/esm');

after(async ()=> {
await remove(path.join(pkgPath, './node_modules'));
});

it('should pass types check', async function () {
this.timeout(30000);

await spawn(`npm test --prefix ${pkgPath}`, [], {
shell : true,
stdio: 'pipe'
});
Comment on lines +159 to +162

Check warning

Code scanning / CodeQL

Superfluous trailing arguments

Superfluous argument passed to [function spawn](1).
});
});

describe('CommonJS', ()=> {
const pkgPath = path.join(__dirname, './typings/cjs');

after(async ()=> {
await remove(path.join(pkgPath, './node_modules'));
});

it('should pass types check', async function () {
this.timeout(30000);

await spawn(`npm test --prefix ${pkgPath}`, [], {
shell : true,
stdio: 'pipe'
});
Comment on lines +176 to +179

Check warning

Code scanning / CodeQL

Superfluous trailing arguments

Superfluous argument passed to [function spawn](1).
});
});
});
});