Skip to content

Commit

Permalink
enable noImplicitAny and disable skipLibCheck in TS compiler (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Jun 27, 2018
1 parent e25e1d9 commit fba7391
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/compiler/test-file/formats/typescript/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default class TypeScriptTestFileCompiler extends APIBasedTestFileCompiler
allowJs: true,
pretty: true,
inlineSourceMap: true,
noImplicitAny: false,
noImplicitAny: true,
module: ts.ModuleKind.CommonJS,
target: 2 /* ES6 */,
lib: ['lib.es6.d.ts'],
baseUrl: __dirname,
paths: { testcafe: ['../../../../../ts-defs/index.d.ts'] },
suppressOutputPathCheck: true,
skipLibCheck: true
skipLibCheck: false
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/server/data/test-suites/typescript-basic/testfile1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('Fixture2Test1', async() => {

// Decorators
function foo () {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
Object.assign({}, { msg: `target is ${target}` });
};
}
Expand Down
14 changes: 7 additions & 7 deletions test/server/data/test-suites/typescript-defs/client-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('Dispatch', async() => {
});

test('Call with arguments', async() => {
const getElementText = ClientFunction((className, idx) => {
const getElementText = ClientFunction((className: string, idx: number) => {
return document.querySelectorAll('.' + className)[idx].textContent;
});

Expand Down Expand Up @@ -91,11 +91,11 @@ test('Error in Promise', async() => {
await fn();
});

const selectByClassName = ClientFunction(className => document.querySelectorAll('.' + className));
const nthByClass = ClientFunction((className, n) => selectByClassName(className)[n], {dependencies: {selectByClassName}});
const selectByClassName: any = ClientFunction((className: string) => document.querySelectorAll('.' + className));
const nthByClass = ClientFunction((className: string, n: number) => selectByClassName(className)[n], {dependencies: {selectByClassName}});

test('ClientFunction call with complex argument types', async() => {
const fn = ClientFunction((re, err, undef, nan) => {
const fn = ClientFunction((re: any, err: any, undef: any, nan: any) => {
return re instanceof RegExp &&
re.source === '\\S+' &&
err instanceof Error &&
Expand Down Expand Up @@ -131,20 +131,20 @@ test('ClientFunction with function argument', async() => {
});
}

const hfn = ClientFunction(fn => fn());
const hfn = ClientFunction((fn: Function) => fn());
const answer = await hfn(getAnswer);

expect(answer).eql(42);
});

test('Async/await in function argument of ClientFunction', async() => {
const hfn = ClientFunction(fn => fn());
const hfn = ClientFunction((fn: Function) => fn());

await hfn(async() => Promise.resolve());
});

test('ClientFunction with ClientFunction argument', async() => {
const hfn = ClientFunction(fn => fn());
const hfn = ClientFunction((fn: Function) => fn());
const location = await hfn(getLocation);

expect(location).eql('http://localhost:3000/fixtures/api/es-next/client-function/pages/index.html');
Expand Down
29 changes: 20 additions & 9 deletions test/server/data/test-suites/typescript-defs/request-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,47 @@ class CustomRequestHook extends RequestHook {
super();
}

onRequest(event) {
onRequest (event: object) {

}

onResponse(event) {
onResponse (event: object) {

}
}

const customHook = new CustomRequestHook();
const logger = RequestLogger('example.com', {logRequestBody: true});
const logger1 = RequestLogger('example.com', {logRequestBody: true});

const logger2 = RequestLogger(req => {
return req.url === 'example.com';
});

const mock = RequestMock()
.onRequestTo(/example.com/)
.respond()
.onRequestTo({url: 'https://example.com'})
.respond(null, 204)
.onRequestTo('https://example.com')
.respond(null, 200, {'x-frame-options': 'deny'});
.respond(null, 200, {'x-frame-options': 'deny'})
.onRequestTo(req => {
return req.url === 'https://example.com';
}).respond((req, res) => {
if (req.url === 'https://example.com')
res.statusCode = '200';
});


fixture `Request Hooks`
.requestHooks(mock, logger, customHook);
.requestHooks(mock, logger1, logger2, customHook);

test
.requestHooks(logger)
.requestHooks(logger1)
('Request hook', async t => {
await t
.addRequestHooks(mock)
.removeRequestHooks(mock)
.expect(logger.contains(t => t.request.statusCode === 200)).ok()
.expect(logger.count(t => t.request.statusCode === 200)).eql(1)
.expect(logger.requests[0].request.body === 'test').ok();
.expect(logger1.contains((t: any) => t.request.statusCode === 200)).ok()
.expect(logger1.count((t: any) => t.request.statusCode === 200)).eql(1)
.expect(logger1.requests[0].request.body === 'test').ok();
});
28 changes: 14 additions & 14 deletions test/server/data/test-suites/typescript-defs/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ test('Combination of filter methods', async t => {
expect(el.id).eql('el4');

// Selector should maintain filter when used as parameter
const getId = ClientFunction(getEl => getEl().id);
const getId = ClientFunction((getEl: Function) => getEl().id);

let id = await getId(selector);

Expand Down Expand Up @@ -708,30 +708,30 @@ test('Selector "count" and "exists" properties', async() => {
expect(await Selector('form').find('input').count).eql(2);
expect(await Selector('.notexists').count).eql(0);

const witClass = Selector(className => document.getElementsByClassName(className));
const withClass = Selector(className => document.getElementsByClassName(className));

expect(await witClass('idxEl').count).eql(4);
expect(await witClass('idxEl').withText('Hey?!').count).eql(2);
expect(await withClass('idxEl').count).eql(4);
expect(await withClass('idxEl').withText('Hey?!').count).eql(2);

expect(await Selector('.idxEl').exists).to.be.true;
expect(await Selector('.idxEl').nth(2).exists).to.be.true;
expect(await Selector('form').find('input').exists).to.be.true;
expect(await Selector('.notexists').exists).to.be.false;
expect(await witClass('idxEl').exists).to.be.true;
expect(await witClass('idxEl').withText('Hey?!').exists).to.be.true;
expect(await witClass('idxEl').withText('testtesttest').exists).to.be.false;
expect(await withClass('idxEl').exists).to.be.true;
expect(await withClass('idxEl').withText('Hey?!').exists).to.be.true;
expect(await withClass('idxEl').withText('testtesttest').exists).to.be.false;
});

test('Selector filter dependencies and index argument', async t => {
const isOne = ClientFunction(i => i === 1);
const isTwo = ClientFunction(i => i === 2);
const firstNode = ClientFunction((node, i) => isOne(i));
const isOne = ClientFunction((i: number) => i === 1);
const isTwo = ClientFunction((i: number) => i === 2);
const firstNode = ClientFunction((node: Node, i: number) => isOne(i));

await t
.expect(Selector('.idxEl').filter((node, i) => !!isTwo(i), {isTwo}).id).eql('el3')
.expect(Selector('.find-parent').find((node, i) => !!isOne(i), {isOne}).id).eql('find-child2')
.expect(Selector('#childDiv').parent((node, i) => !!isTwo(i), {isTwo}).id).eql('p2')
.expect(Selector('.find-parent').child((node, i) => !!isOne(i), {isOne}).id).eql('find-child3');
.expect(Selector('.idxEl').filter((node: Node, i: number) => !!isTwo(i), {isTwo}).id).eql('el3')
.expect(Selector('.find-parent').find((node: Node, i: number) => !!isOne(i), {isOne}).id).eql('find-child2')
.expect(Selector('#childDiv').parent((node: Node, i: number) => !!isTwo(i), {isTwo}).id).eql('p2')
.expect(Selector('.find-parent').child((node: Node, i: number) => !!isOne(i), {isOne}).id).eql('find-child3');
});

test('Selector filter origin node argument', async t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test('Get UA', async t => {
throw await t.eval(() => navigator.userAgent);
});

const getById = ClientFunction(id => document.getElementById(id));
const getById = ClientFunction((id: string) => document.getElementById(id));


test('Eval with dependencies', async t => {
Expand Down Expand Up @@ -463,7 +463,7 @@ test('Expected confirm after an action', async t => {
});

test('Expected confirm after an action (with dependencies)', async t => {
var dialogHandler = ClientFunction((type, text) => {
var dialogHandler = ClientFunction((type: string, text: string) => {
if (type === 'confirm' && text === 'Confirm?')
return true;

Expand All @@ -478,7 +478,7 @@ test('Expected confirm after an action (with dependencies)', async t => {
});

test('Expected confirm after an action (client function)', async t => {
var dialogHandler = ClientFunction((type, text) => {
var dialogHandler = ClientFunction((type: string, text: string) => {
if (type === 'confirm' && text === 'Confirm?')
return true;

Expand Down
6 changes: 3 additions & 3 deletions ts-defs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,14 @@ interface RequestMock {
* Specifies requests to intercept
* @param filter - Specifies which requests should be mocked with a response that follows in the `respond` method.
*/
onRequestTo(filter: string | RegExp | object | ((req, res) => boolean)): RequestMock;
onRequestTo(filter: string | RegExp | object | ((req: any) => boolean)): RequestMock;
/**
* Specifies the mocked response.
* @param body - The mocked response body.
* @param statusCode - The response status code.
* @param headers - Custom headers added to the response in the property-value form.
*/
respond(body?: object | string | ((req, res) => any), statusCode?: number, headers?: object): RequestMock;
respond(body?: object | string | ((req: any, res: any) => any), statusCode?: number, headers?: object): RequestMock;
}

interface Request {
Expand Down Expand Up @@ -1570,7 +1570,7 @@ declare module 'testcafe' {
/**
* Creates a request logger
*/
export function RequestLogger(filter?: string | RegExp | object | ((req, res) => boolean), options?: RequestLoggerOptions): RequestLogger;
export function RequestLogger(filter?: string | RegExp | object | ((req: any) => boolean), options?: RequestLoggerOptions): RequestLogger;

/** The RequestHook class used to create a custom HTTP request hook **/
export class RequestHook {
Expand Down

0 comments on commit fba7391

Please sign in to comment.