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

Greater Coverage in Tests #7395

Merged
merged 16 commits into from
Jan 6, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/amazon-cognito-identity-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"es",
"lib"
]
}
}
30 changes: 30 additions & 0 deletions packages/analytics/__tests__/utils-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { isAppInForeground } from '../src/utils/AppUtils';
import MethodEmbed from '../src/utils/MethodEmbed';

jest.mock('../src/utils/AppUtils.native', () => {
return {
isAppInForeground: jest.fn(),
};
});

describe('Utils', () => {
test('inAppInForeground', () => {
expect(isAppInForeground()).toBe(true);
});

test('MethodEmbed', () => {
const set = new Set();
const methodEmbed = new MethodEmbed(set, 'add');
expect(methodEmbed instanceof MethodEmbed).toBe(true);
methodEmbed.set(() => {
return 'override';
});
methodEmbed.remove();
MethodEmbed.add(set, 'add', () => {
return 'override';
});
MethodEmbed.remove(set, 'add');
expect(methodEmbed.context).toBe(set);
expect(methodEmbed.methodName).toBe('add');
});
});
5 changes: 4 additions & 1 deletion packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
],
"setupFiles": [
"<rootDir>/src/setupTests.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
import { RequestParams, SessionInfo } from './DataType';
import { RequestParams } from './DataType';

enum HTML5_MEDIA_EVENT {
'PLAY' = 'play',
Expand Down
5 changes: 4 additions & 1 deletion packages/api-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
]
}
}
5 changes: 4 additions & 1 deletion packages/api-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
]
}
}
5 changes: 4 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
]
}
}
5 changes: 4 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
],
"testSequencer": "./testSequencer.js"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/OAuth/urlOpener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const SELF = '_self';

export const launchUri = url => {
export const launchUri = (url: string) => {
const windowProxy = window.open(url, SELF);
if (windowProxy) {
return Promise.resolve(windowProxy);
Expand Down
5 changes: 4 additions & 1 deletion packages/aws-amplify-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
],
"moduleNameMapper": {
"\\.(css|less|scss|sass)$": "<rootDir>/__mocks__/styleMock.ts"
Expand Down
1 change: 1 addition & 0 deletions packages/aws-amplify-vue/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ module.exports = {
collectCoverage: true,
coverageReporters: ['lcov'],
setupTestFrameworkScriptFile: '<rootDir>/test_setup/setup-jest.ts',
coveragePathIgnorePatterns: ['/node_modules/', 'dist'],
};
5 changes: 4 additions & 1 deletion packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
]
}
}
5 changes: 4 additions & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@
}
},
"coveragePathIgnorePatterns": [
"/node_modules/"
"/node_modules/",
"dist",
"lib",
"lib-esm"
]
}
}
59 changes: 59 additions & 0 deletions packages/core/__tests__/ClientDevice-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ClientDevice } from '../src/ClientDevice';
import { browserType } from '../src/ClientDevice/browser';

describe('ClientDevice', () => {
test('clientInfo', () => {
expect(ClientDevice.clientInfo()).toBeInstanceOf(Object);
});

test('clientInfo', () => {
const dimensions = ClientDevice.dimension();
expect(typeof dimensions.width).toBe('number');
expect(typeof dimensions.height).toBe('number');
});
});

describe('browserType', () => {
test('opera', () => {
expect(
browserType(
'Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00'
)
).toStrictEqual({
type: 'n',
version: '10.00',
});
});

test('ie', () => {
expect(
browserType(`Internet Explorer 10
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)`)
).toStrictEqual({
type: 'Trident',
version: '6.0',
});
});

test('safari', () => {
expect(
browserType(
`Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1`
)
).toStrictEqual({
type: 'Safari',
version: '604.1',
});
});

test('chrome', () => {
expect(
browserType(
`Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36`
)
).toStrictEqual({
type: 'Chrome',
version: '51.0.2704.103',
});
});
});
17 changes: 17 additions & 0 deletions packages/core/__tests__/Errors-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { missingConfig, invalidParameter } from '../src/Errors';

describe('Error', () => {
test('Missing Config', () => {
const missingConfigError = missingConfig('someField');
expect(missingConfigError.message).toEqual(
'Missing config value of someField'
);
});

test('Invalid Param', () => {
const invalidParameterError = invalidParameter('someArg');
expect(invalidParameterError.message).toEqual(
'Invalid parameter value of someArg'
);
});
});
23 changes: 23 additions & 0 deletions packages/core/__tests__/MemoryStorage-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import StorageHelperDefault, {
MemoryStorage,
StorageHelper,
} from '../src/StorageHelper';

describe('StorageHelper', () => {
test('MemoryStorage', () => {
MemoryStorage.setItem('k', 'v');
expect(MemoryStorage.getItem('k')).toEqual('v');
MemoryStorage.removeItem('k');
expect(MemoryStorage.getItem('k')).toBeFalsy();
MemoryStorage.setItem('k', 'v');
MemoryStorage.clear();
expect(MemoryStorage.getItem('k')).toBeFalsy();
});

test('StorageHelper', () => {
const helperA = new StorageHelperDefault().getStorage();
expect(helperA instanceof Storage).toBeTruthy();
const helperB = new StorageHelper().getStorage();
expect(helperB instanceof Storage).toBeTruthy();
});
});
16 changes: 8 additions & 8 deletions packages/core/__tests__/ServiceWorker-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ServiceWorker test', () => {
return expect(enablePush).toThrow('Service Worker not registered');
});
test('fails when registering', async () => {
global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.reject('an error'),
};

Expand All @@ -36,7 +36,7 @@ describe('ServiceWorker test', () => {
statuses.forEach(status => {
test(`can register (${status})`, () => {
const bla = { [status]: { addEventListener: () => {} } };
global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand All @@ -52,7 +52,7 @@ describe('ServiceWorker test', () => {
[status]: { addEventListener: jest.fn() },
};

global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand All @@ -69,7 +69,7 @@ describe('ServiceWorker test', () => {
installing: { postMessage: jest.fn(), addEventListener: jest.fn() },
};

global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand All @@ -84,7 +84,7 @@ describe('ServiceWorker test', () => {
installing: { postMessage: jest.fn(), addEventListener: jest.fn() },
};

global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand All @@ -100,7 +100,7 @@ describe('ServiceWorker test', () => {
installing: { postMessage: jest.fn(), addEventListener: jest.fn() },
};

global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand All @@ -127,7 +127,7 @@ describe('ServiceWorker test', () => {
},
};

global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand All @@ -149,7 +149,7 @@ describe('ServiceWorker test', () => {
},
};

global.navigator.serviceWorker = {
(global as any).navigator.serviceWorker = {
register: () => Promise.resolve(bla),
};

Expand Down
43 changes: 43 additions & 0 deletions packages/core/__tests__/Util-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,53 @@ import { jitteredExponentialRetry, NonRetryableError } from '../src/Util';
import ReachabilityNative from '../src/Util/Reachability.native';
import Reachability from '../src/Util/Reachability';
import { ConsoleLogger as Logger } from '../src/Logger';
import { urlSafeDecode, urlSafeEncode } from '../src/Util/StringUtils';
import { DateUtils } from '../src/Util/DateUtils';

Logger.LOG_LEVEL = 'DEBUG';

describe('Util', () => {
beforeEach(() => {});

describe('DateUtils', () => {
test('isClockSkewError', () => {
expect(
DateUtils.isClockSkewError({
response: {
headers: {
'x-amzn-errortype': 'BadRequestException',
date: true,
},
},
})
).toBeTruthy();
});

test('', () => {
DateUtils.setClockOffset(1000);
expect(DateUtils.getClockOffset()).toBe(1000);
DateUtils.setClockOffset(0);
const date = new Date();
const header = DateUtils.getHeaderStringFromDate(date);
const fromHeader = DateUtils.getDateFromHeaderString(header);
expect(date.toTimeString()).toEqual(fromHeader.toTimeString());
});
});

describe('StringUtils', () => {
test('urlSafeEncode', () => {
expect(urlSafeEncode('some/path?to-whatever')).toBe(
'736f6d652f706174683f746f2d7768617465766572'
);
});

test('urlSafeDecode', () => {
expect(urlSafeDecode('736f6d652f706174683f746f2d7768617465766572')).toBe(
'some/path?to-whatever'
);
});
});

test('jitteredExponential retry happy case', done => {
const resolveAt = 3;
expect.assertions(3);
Expand Down
Loading