From 2362dcf9441df46e00c93e6480b5f99b0abe3553 Mon Sep 17 00:00:00 2001 From: Aditya Date: Mon, 7 Oct 2019 16:08:44 +0200 Subject: [PATCH] Convert aws-amplify-vue to Typescript --- package.json | 7 +- .../amazon-cognito-identity-js/index.d.ts | 20 +- packages/api/src/API.ts | 15 +- packages/auth/src/Auth.ts | 5 +- .../__mocks__/Amplify.mocks.js | 64 ----- .../__mocks__/Amplify.mocks.ts | 64 +++++ .../{Amplify.test.js => Amplify.test.ts} | 6 +- ...fyPlugin.test.js => AmplifyPlugin.test.ts} | 4 +- ...nticator.test.js => Authenticator.test.ts} | 43 ++-- .../{Chatbot.test.js => Chatbot.test.ts} | 26 ++- ...rmSignIn.test.js => ConfirmSignIn.test.ts} | 33 ++- ...rmSignUp.test.js => ConfirmSignUp.test.ts} | 23 +- .../aws-amplify-vue/__tests__/Connect.test.js | 31 --- .../aws-amplify-vue/__tests__/Connect.test.ts | 38 +++ ...assword.test.js => ForgotPassword.test.ts} | 20 +- .../{GetUser.test.js => GetUser.test.ts} | 16 +- ...{PhoneField.test.js => PhoneField.test.ts} | 14 +- ...hotoPicker.test.js => PhotoPicker.test.ts} | 25 +- ...ord.test.js => RequireNewPassword.test.ts} | 25 +- .../{S3Album.test.js => S3Album.test.ts} | 14 +- .../{S3Image.test.js => S3Image.test.ts} | 16 +- .../{SetMFA.test.js => SetMFA.test.ts} | 26 ++- .../{SignIn.test.js => SignIn.test.ts} | 22 +- .../{SignOut.test.js => SignOut.test.ts} | 18 +- .../{SignUp.test.js => SignUp.test.ts} | 25 +- ...ianScene.test.js => SumerianScene.test.ts} | 8 +- ...ameField.test.js => UsernameField.test.ts} | 18 +- packages/aws-amplify-vue/jest.config.js | 34 ++- packages/aws-amplify-vue/package.json | 12 +- packages/aws-amplify-vue/src/Amplify.vue | 12 +- .../aws-amplify-vue/src/assets/countries.js | 220 ------------------ .../aws-amplify-vue/src/assets/countries.ts | 218 +++++++++++++++++ .../src/assets/data-test-attributes.js | 162 ------------- .../src/assets/data-test-attributes.ts | 162 +++++++++++++ .../src/assets/default-sign-up-fields.js | 84 ------- .../src/assets/default-sign-up-fields.ts | 95 ++++++++ .../src/components/api/graphql/Connect.vue | 85 ++++--- .../src/components/api/{index.js => index.ts} | 0 .../authenticator/Authenticator.vue | 102 +++++--- .../authenticator/ConfirmSignIn.vue | 88 ++++--- .../authenticator/ConfirmSignUp.vue | 101 ++++---- .../authenticator/ForgotPassword.vue | 119 +++++----- .../components/authenticator/PhoneField.vue | 89 +++---- .../authenticator/RequireNewPassword.vue | 136 ++++++----- .../src/components/authenticator/SetMFA.vue | 164 +++++++------ .../src/components/authenticator/SignIn.vue | 163 ++++++------- .../src/components/authenticator/SignOut.vue | 66 +++--- .../src/components/authenticator/SignUp.vue | 175 +++++++------- .../authenticator/UsernameField.vue | 144 ++++++------ .../authenticator/{common.js => common.ts} | 8 +- .../authenticator/{index.js => index.ts} | 20 +- .../aws-amplify-vue/src/components/base.ts | 71 ++++++ .../src/components/{index.js => index.ts} | 0 .../src/components/interactions/Chatbot.vue | 173 ++++++++------ .../interactions/aws-lex-audio-shim.ts | 29 +++ .../components/interactions/aws-lex-audio.js | 1 + .../interactions/{index.js => index.ts} | 4 +- .../src/components/storage/PhotoPicker.vue | 113 +++++---- .../src/components/storage/S3Album.vue | 102 ++++---- .../src/components/storage/S3Image.vue | 73 +++--- .../components/storage/{index.js => index.ts} | 2 - .../src/components/xr/SumerianScene.vue | 95 +++++--- .../src/components/xr/{index.js => index.ts} | 0 ...{AmplifyEventBus.js => AmplifyEventBus.ts} | 0 .../{AmplifyPlugin.js => AmplifyPlugin.ts} | 38 +-- .../src/services/{getUser.js => getUser.ts} | 25 +- packages/aws-amplify-vue/src/shims-vue.d.ts | 4 + .../aws-amplify-vue/test_setup/setup-jest.ts | 35 ++- packages/aws-amplify-vue/tsconfig.json | 29 +++ packages/aws-amplify-vue/tslint.json | 50 ++++ packages/aws-amplify-vue/vue.config.js | 1 - .../core/src/OAuthHelper/FacebookOAuth.ts | 9 +- packages/core/src/OAuthHelper/GoogleOAuth.ts | 10 +- .../core/src/ServiceWorker/ServiceWorker.ts | 6 +- 74 files changed, 2219 insertions(+), 1736 deletions(-) delete mode 100644 packages/aws-amplify-vue/__mocks__/Amplify.mocks.js create mode 100644 packages/aws-amplify-vue/__mocks__/Amplify.mocks.ts rename packages/aws-amplify-vue/__tests__/{Amplify.test.js => Amplify.test.ts} (79%) rename packages/aws-amplify-vue/__tests__/{AmplifyPlugin.test.js => AmplifyPlugin.test.ts} (77%) rename packages/aws-amplify-vue/__tests__/{Authenticator.test.js => Authenticator.test.ts} (74%) rename packages/aws-amplify-vue/__tests__/{Chatbot.test.js => Chatbot.test.ts} (89%) rename packages/aws-amplify-vue/__tests__/{ConfirmSignIn.test.js => ConfirmSignIn.test.ts} (83%) rename packages/aws-amplify-vue/__tests__/{ConfirmSignUp.test.js => ConfirmSignUp.test.ts} (87%) delete mode 100644 packages/aws-amplify-vue/__tests__/Connect.test.js create mode 100644 packages/aws-amplify-vue/__tests__/Connect.test.ts rename packages/aws-amplify-vue/__tests__/{ForgotPassword.test.js => ForgotPassword.test.ts} (88%) rename packages/aws-amplify-vue/__tests__/{GetUser.test.js => GetUser.test.ts} (68%) rename packages/aws-amplify-vue/__tests__/{PhoneField.test.js => PhoneField.test.ts} (76%) rename packages/aws-amplify-vue/__tests__/{PhotoPicker.test.js => PhotoPicker.test.ts} (88%) rename packages/aws-amplify-vue/__tests__/{RequireNewPassword.test.js => RequireNewPassword.test.ts} (86%) rename packages/aws-amplify-vue/__tests__/{S3Album.test.js => S3Album.test.ts} (82%) rename packages/aws-amplify-vue/__tests__/{S3Image.test.js => S3Image.test.ts} (83%) rename packages/aws-amplify-vue/__tests__/{SetMFA.test.js => SetMFA.test.ts} (91%) rename packages/aws-amplify-vue/__tests__/{SignIn.test.js => SignIn.test.ts} (91%) rename packages/aws-amplify-vue/__tests__/{SignOut.test.js => SignOut.test.ts} (87%) rename packages/aws-amplify-vue/__tests__/{SignUp.test.js => SignUp.test.ts} (92%) rename packages/aws-amplify-vue/__tests__/{SumerianScene.test.js => SumerianScene.test.ts} (90%) rename packages/aws-amplify-vue/__tests__/{UsernameField.test.js => UsernameField.test.ts} (88%) delete mode 100644 packages/aws-amplify-vue/src/assets/countries.js create mode 100644 packages/aws-amplify-vue/src/assets/countries.ts delete mode 100644 packages/aws-amplify-vue/src/assets/data-test-attributes.js create mode 100644 packages/aws-amplify-vue/src/assets/data-test-attributes.ts delete mode 100644 packages/aws-amplify-vue/src/assets/default-sign-up-fields.js create mode 100644 packages/aws-amplify-vue/src/assets/default-sign-up-fields.ts rename packages/aws-amplify-vue/src/components/api/{index.js => index.ts} (100%) rename packages/aws-amplify-vue/src/components/authenticator/{common.js => common.ts} (82%) rename packages/aws-amplify-vue/src/components/authenticator/{index.js => index.ts} (90%) create mode 100644 packages/aws-amplify-vue/src/components/base.ts rename packages/aws-amplify-vue/src/components/{index.js => index.ts} (100%) create mode 100644 packages/aws-amplify-vue/src/components/interactions/aws-lex-audio-shim.ts rename packages/aws-amplify-vue/src/components/interactions/{index.js => index.ts} (90%) rename packages/aws-amplify-vue/src/components/storage/{index.js => index.ts} (95%) rename packages/aws-amplify-vue/src/components/xr/{index.js => index.ts} (100%) rename packages/aws-amplify-vue/src/events/{AmplifyEventBus.js => AmplifyEventBus.ts} (100%) rename packages/aws-amplify-vue/src/plugins/{AmplifyPlugin.js => AmplifyPlugin.ts} (53%) rename packages/aws-amplify-vue/src/services/{getUser.js => getUser.ts} (60%) create mode 100644 packages/aws-amplify-vue/src/shims-vue.d.ts create mode 100644 packages/aws-amplify-vue/tsconfig.json create mode 100644 packages/aws-amplify-vue/tslint.json diff --git a/package.json b/package.json index 9b087941fa6..9d8a6763a22 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,10 @@ "pre-commit": "pretty-quick --staged" } }, - "workspaces": [ - "packages/*" - ], + "workspaces": { + "packages": ["packages/*"], + "nohoist": ["**/@vue/**"] + }, "repository": { "type": "git", "url": "https://github.com/aws-amplify/amplify-js.git" diff --git a/packages/amazon-cognito-identity-js/index.d.ts b/packages/amazon-cognito-identity-js/index.d.ts index 707055e551d..478dcd15075 100644 --- a/packages/amazon-cognito-identity-js/index.d.ts +++ b/packages/amazon-cognito-identity-js/index.d.ts @@ -57,7 +57,19 @@ declare module 'amazon-cognito-identity-js' { Storage?: ICognitoStorage; } + export type CognitoSigninChallenge = 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA'; + export type CognitoChallenge = + | CognitoSigninChallenge + | 'CUSTOM_CHALLENGE' + | 'DEVICE_SRP_AUTH' + | 'MFA_SETUP' + | 'NEW_PASSWORD_REQUIRED' + | 'SELECT_MFA_TYPE' + | 'DEVICE_PASSWORD_VERIFIER'; + export class CognitoUser { + challengeName?: CognitoChallenge; + constructor(data: ICognitoUserData); public setSignInUserSession( @@ -316,10 +328,10 @@ declare module 'amazon-cognito-identity-js' { public isValid(): boolean; } /* - export class CognitoIdentityServiceProvider { - public config: AWS.CognitoIdentityServiceProvider.Types.ClientConfiguration; - } - */ + export class CognitoIdentityServiceProvider { + public config: AWS.CognitoIdentityServiceProvider.Types.ClientConfiguration; + } + */ export class CognitoAccessToken { payload: { [key: string]: any }; diff --git a/packages/api/src/API.ts b/packages/api/src/API.ts index 38a98e56277..6f65ea29fac 100644 --- a/packages/api/src/API.ts +++ b/packages/api/src/API.ts @@ -10,9 +10,13 @@ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions * and limitations under the License. */ -import { OperationDefinitionNode, GraphQLError } from 'graphql'; -import { print } from 'graphql/language/printer'; -import { parse } from 'graphql/language/parser'; +import { + OperationDefinitionNode, + OperationTypeNode, + GraphQLError, + parse, + print, +} from 'graphql'; import * as Observable from 'zen-observable'; import { RestClient as RestClass } from './RestClient'; import Amplify, { @@ -40,8 +44,7 @@ export default class APIClass { * @private */ private _options; - private _api = null; - private _pubSub = Amplify.PubSub; + private _api: RestClass = null; /** * Initialize Storage with AWS configuration @@ -334,7 +337,7 @@ export default class APIClass { * to get the operation type * @param operation */ - getGraphqlOperationType(operation) { + getGraphqlOperationType(operation: string): OperationTypeNode { const doc = parse(operation); const { definitions: [{ operation: operationType }], diff --git a/packages/auth/src/Auth.ts b/packages/auth/src/Auth.ts index f9c2e4d253a..f2aa2322e96 100644 --- a/packages/auth/src/Auth.ts +++ b/packages/auth/src/Auth.ts @@ -59,6 +59,7 @@ import { CognitoIdToken, CognitoRefreshToken, CognitoAccessToken, + CognitoSigninChallenge, } from 'amazon-cognito-identity-js'; import { parse } from 'url'; @@ -857,7 +858,7 @@ export default class AuthClass { public confirmSignIn( user: CognitoUser | any, code: string, - mfaType?: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA' | null + mfaType?: CognitoSigninChallenge | null ): Promise { if (!code) { return this.rejectAuthError(AuthErrorTypes.EmptyCode); @@ -1767,7 +1768,7 @@ export default class AuthClass { logger.debug('AWS credentials', credentials); } - /* + /* Prior to the request we do sign the custom state along with the state we set. This check will verify if there is a dash indicated when setting custom state from the request. If a dash is contained then there is custom state present on the state string. diff --git a/packages/aws-amplify-vue/__mocks__/Amplify.mocks.js b/packages/aws-amplify-vue/__mocks__/Amplify.mocks.js deleted file mode 100644 index aa47f9534a2..00000000000 --- a/packages/aws-amplify-vue/__mocks__/Amplify.mocks.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = { - Logger: function Logger(name) { - this.name = name; - this.info = jest.fn(); - this.error = jest.fn(); - }, - Auth: { - currentAuthenticatedUser: jest.fn(() => Promise.resolve({})), - verifyCurrentUserAttribute: jest.fn(() => - Promise.resolve({ username: 'myTestUsername' }) - ), - completeNewPassword: jest.fn(() => Promise.resolve({})), - confirmSignIn: jest.fn(() => Promise.resolve({})), - confirmSignUp: jest.fn(() => Promise.resolve({})), - forgotPassword: jest.fn(() => Promise.resolve({})), - forgotPasswordSubmit: jest.fn(() => Promise.resolve({})), - resendSignUp: jest.fn(() => Promise.resolve({})), - setPreferredMFA: jest.fn(() => Promise.resolve({})), - setupTOTP: jest.fn(() => Promise.resolve('gibberish')), - signIn: jest.fn(() => - Promise.resolve({ - challengeName: 'CUSTOM_CHALLENGE', - challengeParam: { trigger: 'true' }, - }) - ), - signOut: jest.fn(() => Promise.resolve({})), - signUp: jest.fn(() => Promise.resolve({})), - verifiedContact: jest.fn(() => Promise.resolve({})), - verifyTotpToken: jest.fn(() => Promise.resolve({})), - }, - AuthClass: {}, - Interactions: { - onComplete: jest.fn(() => Promise.resolve({})), - send: jest.fn(() => Promise.resolve({})), - }, - Storage: { - get: jest.fn(() => Promise.resolve({})), - put: jest.fn(() => Promise.resolve({ key: 'testKey' })), - list: jest.fn(() => Promise.resolve({})), - }, - I18n: { - get: jest.fn(key => { - return `i18n ${key}`; - }), - }, - XR: { - loadScene: jest.fn(() => Promise.resolve({})), - start: jest.fn(), - isMuted: jest.fn(() => { - return false; - }), - isVRCapable: jest.fn(() => { - return false; - }), - onSceneEvent: jest.fn(), - setMuted: jest.fn(), - enableAudio: jest.fn(), - enterVR: jest.fn(), - exitVR: jest.fn(), - isVRPresentationActive: jest.fn(() => { - return false; - }), - }, -}; diff --git a/packages/aws-amplify-vue/__mocks__/Amplify.mocks.ts b/packages/aws-amplify-vue/__mocks__/Amplify.mocks.ts new file mode 100644 index 00000000000..da3bd901f5e --- /dev/null +++ b/packages/aws-amplify-vue/__mocks__/Amplify.mocks.ts @@ -0,0 +1,64 @@ +export class Logger { + private name: string; + public info = jest.fn(); + public error = jest.fn(); + + constructor(name: string) { + this.name = name; + } +}; + +export const Auth = { + currentAuthenticatedUser: jest.fn(() => Promise.resolve({})), + verifyCurrentUserAttribute: jest.fn(() => + Promise.resolve({ username: 'myTestUsername' }) + ), + completeNewPassword: jest.fn(() => Promise.resolve({})), + confirmSignIn: jest.fn(() => Promise.resolve({})), + confirmSignUp: jest.fn(() => Promise.resolve({})), + forgotPassword: jest.fn(() => Promise.resolve({})), + forgotPasswordSubmit: jest.fn(() => Promise.resolve({})), + resendSignUp: jest.fn(() => Promise.resolve({})), + setPreferredMFA: jest.fn(() => Promise.resolve({})), + setupTOTP: jest.fn(() => Promise.resolve('gibberish')), + signIn: jest.fn(() => + Promise.resolve({ + challengeName: 'CUSTOM_CHALLENGE', + challengeParam: { trigger: 'true' }, + }) + ), + signOut: jest.fn(() => Promise.resolve({})), + signUp: jest.fn(() => Promise.resolve({})), + verifiedContact: jest.fn(() => Promise.resolve({})), + verifyTotpToken: jest.fn(() => Promise.resolve({})), +}; + +export class AuthClass {}; + +export const Interactions = { + onComplete: jest.fn(() => Promise.resolve({})), + send: jest.fn(() => Promise.resolve({})), +}; + +export const Storage = { + get: jest.fn(() => Promise.resolve({})), + put: jest.fn(() => Promise.resolve({ key: 'testKey' })), + list: jest.fn(() => Promise.resolve({})), +}; + +export const I18n = { + get: jest.fn(key => `i18n ${key}`), +}; + +export const XR = { + loadScene: jest.fn(() => Promise.resolve({})), + start: jest.fn(), + isMuted: jest.fn(() => false), + isVRCapable: jest.fn(() => false), + onSceneEvent: jest.fn(), + setMuted: jest.fn(), + enableAudio: jest.fn(), + enterVR: jest.fn(), + exitVR: jest.fn(), + isVRPresentationActive: jest.fn(() => false), +}; diff --git a/packages/aws-amplify-vue/__tests__/Amplify.test.js b/packages/aws-amplify-vue/__tests__/Amplify.test.ts similarity index 79% rename from packages/aws-amplify-vue/__tests__/Amplify.test.js rename to packages/aws-amplify-vue/__tests__/Amplify.test.ts index 38d140a00f6..9ecaf5eedd2 100644 --- a/packages/aws-amplify-vue/__tests__/Amplify.test.js +++ b/packages/aws-amplify-vue/__tests__/Amplify.test.ts @@ -1,7 +1,7 @@ import Vue from 'vue'; -import App from '../src/Amplify.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import App from '@/Amplify.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; Vue.use(AmplifyPlugin, AmplifyMocks); diff --git a/packages/aws-amplify-vue/__tests__/AmplifyPlugin.test.js b/packages/aws-amplify-vue/__tests__/AmplifyPlugin.test.ts similarity index 77% rename from packages/aws-amplify-vue/__tests__/AmplifyPlugin.test.js rename to packages/aws-amplify-vue/__tests__/AmplifyPlugin.test.ts index bac10ae1640..f95647af8d0 100644 --- a/packages/aws-amplify-vue/__tests__/AmplifyPlugin.test.js +++ b/packages/aws-amplify-vue/__tests__/AmplifyPlugin.test.ts @@ -1,6 +1,6 @@ import Vue from 'vue'; -import App from '../src/Amplify.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import App from '@/Amplify.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; Vue.use(AmplifyPlugin, {}); diff --git a/packages/aws-amplify-vue/__tests__/Authenticator.test.js b/packages/aws-amplify-vue/__tests__/Authenticator.test.ts similarity index 74% rename from packages/aws-amplify-vue/__tests__/Authenticator.test.js rename to packages/aws-amplify-vue/__tests__/Authenticator.test.ts index 23162fed6d9..bc86d102eab 100644 --- a/packages/aws-amplify-vue/__tests__/Authenticator.test.js +++ b/packages/aws-amplify-vue/__tests__/Authenticator.test.ts @@ -1,26 +1,33 @@ import Vue from 'vue'; -import { shallowMount } from '@vue/test-utils'; // eslint-disable-line -import Authenticator from '../src/components/authenticator/Authenticator.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import * as components from '../src/components'; -import * as AmplifyEntry from '../src/Amplify.vue'; //eslint-disable-line -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import { mocked } from 'ts-jest/utils'; +import { shallowMount } from '@vue/test-utils'; +import Authenticator from '@/components/authenticator/Authenticator.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import * as components from '@/components'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -import dependency from '../src/services/getUser'; +import dependency from '@/services/getUser'; Vue.use(AmplifyPlugin, AmplifyMocks); -jest.mock('../src/services/getUser'); +jest.mock('@/services/getUser'); describe('Authenticator', () => { + let authenticator; + + beforeEach(() => { + authenticator = new Authenticator(); + }); + it('has a mounted hook', () => { - expect(typeof Authenticator.mounted).toBe('function'); + expect(authenticator.$options.mounted.length).toEqual(1); + expect(typeof authenticator.$options.mounted[0]).toBe('function'); }); it('sets the correct default data', () => { - expect(typeof Authenticator.data).toBe('function'); - const defaultData = Authenticator.data(); - expect(defaultData.user.username).toBe(null); - expect(defaultData.logger).toEqual({}); + expect(typeof authenticator.$options.data).toEqual('function'); + const defaultData = authenticator.$options.data(); + expect(defaultData.user).toBe(null); + expect(defaultData.logger).toEqual(null); expect(defaultData.displayMap).toEqual({}); expect(defaultData.error).toEqual(''); }); @@ -30,7 +37,7 @@ describe('Authenticator', () => { beforeEach(() => { wrapper = shallowMount(Authenticator); - dependency.mockImplementation(() => Promise.resolve({})); + mocked(dependency).mockImplementation(() => Promise.resolve(null)); }); it('...it should use the amplify plugin with passed modules', () => { @@ -60,7 +67,7 @@ describe('Authenticator', () => { describe('...when it is mounted and displaying components...', () => { let wrapper; - let mockDisplayMap = {}; + let mockDisplayMap = {} as any; beforeEach(() => { wrapper = shallowMount(Authenticator, { // methods: { @@ -68,7 +75,7 @@ describe('Authenticator', () => { // } }); wrapper.vm.updateDisplayMap = jest.fn(() => mockDisplayMap); - dependency.mockImplementation(() => Promise.reject(new Error())); + mocked(dependency).mockImplementation(() => Promise.reject(new Error())); mockDisplayMap = { showSignIn: false, showSignUp: false, @@ -122,9 +129,9 @@ describe('Authenticator', () => { }); it('...should set user and options data on localUser event emission', () => { - const testUser = { username: 'IAMEMITTED' }; + const testUser = { getUsername: () => 'IAMEMITTED' }; AmplifyEventBus.$emit('localUser', testUser); - expect(wrapper.vm.user.username).toEqual(testUser.username); + expect(wrapper.vm.user.getUsername()).toEqual(testUser.getUsername()); }); }); }); diff --git a/packages/aws-amplify-vue/__tests__/Chatbot.test.js b/packages/aws-amplify-vue/__tests__/Chatbot.test.ts similarity index 89% rename from packages/aws-amplify-vue/__tests__/Chatbot.test.js rename to packages/aws-amplify-vue/__tests__/Chatbot.test.ts index a638e1aa88b..c80e07a4115 100644 --- a/packages/aws-amplify-vue/__tests__/Chatbot.test.js +++ b/packages/aws-amplify-vue/__tests__/Chatbot.test.ts @@ -1,26 +1,30 @@ -/* eslint-disable */ import Vue from 'vue'; -import { shallowMount, mount } from '@vue/test-utils'; -import * as AmplifyUI from '@aws-amplify/ui'; -import Chatbot from '../src/components/interactions/Chatbot.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import { shallowMount } from '@vue/test-utils'; +import Chatbot from '@/components/interactions/Chatbot.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('Chatbot', () => { + let chatbot; + + beforeEach(() => { + chatbot = new Chatbot(); + }); + it('has a mounted hook', () => { - expect(typeof Chatbot.mounted).toBe('function'); + expect(chatbot.$options.mounted.length).toEqual(1); + expect(typeof chatbot.$options.mounted[0]).toBe('function'); }); it('sets the correct default data', () => { - expect(typeof Chatbot.data).toBe('function'); - const defaultData = Chatbot.data(); + expect(typeof chatbot.$options.data).toBe('function'); + const defaultData = chatbot.$options.data(); expect(defaultData.inputText).toBe(''); expect(defaultData.messages.length).toEqual(0); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); diff --git a/packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.js b/packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.ts similarity index 83% rename from packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.js rename to packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.ts index 0fbceeaef4d..4587be833dc 100644 --- a/packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.js +++ b/packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.ts @@ -1,25 +1,30 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import ConfirmSignIn from '../src/components/authenticator/ConfirmSignIn.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import ConfirmSignIn from '@/components/authenticator/ConfirmSignIn.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('ConfirmSignIn', () => { + let confirmSignIn; + + beforeEach(() => { + confirmSignIn = new ConfirmSignIn(); + }); + it('has a mounted hook', () => { - expect(typeof ConfirmSignIn.mounted).toBe('function'); + expect(confirmSignIn.$options.mounted.length).toEqual(1); + expect(typeof confirmSignIn.$options.mounted[0]).toBe('function'); }); it('sets the correct default data', () => { - expect(typeof ConfirmSignIn.data).toBe('function'); - const defaultData = ConfirmSignIn.data(); + expect(typeof confirmSignIn.$options.data).toBe('function'); + const defaultData = confirmSignIn.$options.data(); expect(defaultData.code).toBe(''); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); @@ -33,7 +38,13 @@ describe('ConfirmSignIn', () => { describe('...when it is mounted without props...', () => { beforeEach(() => { - wrapper = shallowMount(ConfirmSignIn); + wrapper = shallowMount(ConfirmSignIn, { + propsData: { + confirmSignInConfig: { + user: {} + } + } + }); }); it('...it should use the amplify plugin with passed modules', () => { @@ -62,7 +73,7 @@ describe('ConfirmSignIn', () => { it('...have default options', () => { expect(wrapper.vm.options.header).toEqual('i18n Confirm Sign In'); - expect(Object.keys(wrapper.vm.options.user).length).toEqual(0); + expect(wrapper.vm.options.user).toEqual({}); }); it('...should set the error property when a valid user is not received', () => { diff --git a/packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.js b/packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.ts similarity index 87% rename from packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.js rename to packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.ts index 669c1e259f4..dfbd535f7e2 100644 --- a/packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.js +++ b/packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.ts @@ -1,25 +1,30 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import ConfirmSignUp from '../src/components/authenticator/ConfirmSignUp.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import ConfirmSignUp from '@/components/authenticator/ConfirmSignUp.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('ConfirmSignUp', () => { + let confirmSignUp; + + beforeEach(() => { + confirmSignUp = new ConfirmSignUp(); + }); + it('has a mounted hook', () => { - expect(typeof ConfirmSignUp.mounted).toBe('function'); + expect(confirmSignUp.$options.mounted.length).toEqual(1); + expect(typeof confirmSignUp.$options.mounted[0]).toBe('function'); }); it('sets the correct default data', () => { - expect(typeof ConfirmSignUp.data).toBe('function'); - const defaultData = ConfirmSignUp.data(); + expect(typeof confirmSignUp.$options.data).toBe('function'); + const defaultData = confirmSignUp.$options.data(); expect(defaultData.code).toBe(''); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); diff --git a/packages/aws-amplify-vue/__tests__/Connect.test.js b/packages/aws-amplify-vue/__tests__/Connect.test.js deleted file mode 100644 index ef9fad2eb4c..00000000000 --- a/packages/aws-amplify-vue/__tests__/Connect.test.js +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-disable */ -import Vue from 'vue'; -import { shallowMount } from '@vue/test-utils'; -import Connect from '../src/components/api/graphql/Connect.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; -import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ - -Vue.use(AmplifyPlugin, AmplifyMocks); - -describe('Connect', () => { - it('has a beforeMount hook', () => { - expect(typeof Connect.beforeMount).toBe('function'); - }); - - it('has a beforeDestroy book', () => { - expect(typeof Connect.beforeDestroy).toBe('function'); - }); - - it('sets the correct default data', () => { - expect(typeof Connect.data).toBe('function'); - const defaultData = Connect.data(); - expect(defaultData.data).toEqual({}); - expect(defaultData.logger).toEqual({}); - expect(defaultData.errors).toEqual([]); - expect(defaultData.loading).toEqual(false); - expect(defaultData.watchedSubscription).toEqual(null); - expect(defaultData.isMutation).toEqual(false); - expect(defaultData.internalMutation).toEqual(null); - }); -}); diff --git a/packages/aws-amplify-vue/__tests__/Connect.test.ts b/packages/aws-amplify-vue/__tests__/Connect.test.ts new file mode 100644 index 00000000000..abdbdc2460a --- /dev/null +++ b/packages/aws-amplify-vue/__tests__/Connect.test.ts @@ -0,0 +1,38 @@ +import Vue from 'vue'; +import { shallowMount } from '@vue/test-utils'; +import Connect from '@/components/api/graphql/Connect.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; +import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; + +Vue.use(AmplifyPlugin, AmplifyMocks); + +describe('Connect', () => { + let connect; + + beforeEach(() => { + connect = new Connect(); + }); + + it('has a beforeMount hook', () => { + expect(connect.$options.beforeMount.length).toEqual(2); + expect(typeof connect.$options.beforeMount[0]).toBe('function'); + expect(typeof connect.$options.beforeMount[1]).toBe('function'); + }); + + it('has a beforeDestroy hook', () => { + expect(connect.$options.beforeDestroy.length).toEqual(1); + expect(typeof connect.$options.beforeDestroy[0]).toBe('function'); + }); + + it('sets the correct default data', () => { + expect(typeof connect.$options.data).toBe('function'); + const defaultData = connect.$options.data(); + expect(defaultData.data).toEqual({}); + expect(defaultData.logger).toEqual(null); + expect(defaultData.errors).toEqual([]); + expect(defaultData.loading).toEqual(false); + expect(defaultData.watchedSubscription).toEqual(null); + expect(defaultData.isMutation).toEqual(false); + expect(defaultData.internalMutation).toEqual(null); + }); +}); diff --git a/packages/aws-amplify-vue/__tests__/ForgotPassword.test.js b/packages/aws-amplify-vue/__tests__/ForgotPassword.test.ts similarity index 88% rename from packages/aws-amplify-vue/__tests__/ForgotPassword.test.js rename to packages/aws-amplify-vue/__tests__/ForgotPassword.test.ts index fbcd5fe55bf..dec714cfd6f 100644 --- a/packages/aws-amplify-vue/__tests__/ForgotPassword.test.js +++ b/packages/aws-amplify-vue/__tests__/ForgotPassword.test.ts @@ -1,25 +1,25 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import ForgotPassword from '../src/components/authenticator/ForgotPassword.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import ForgotPassword from '@/components/authenticator/ForgotPassword.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('ForgotPassword', () => { - it('has a mounted hook', () => { - expect(typeof ForgotPassword.mounted).toBe('function'); + let forgotPassword; + + beforeEach(() => { + forgotPassword = new ForgotPassword(); }); it('sets the correct default data', () => { - expect(typeof ForgotPassword.data).toBe('function'); - const defaultData = ForgotPassword.data(); + expect(typeof forgotPassword.$options.data).toBe('function'); + const defaultData = forgotPassword.$options.data(); expect(defaultData.code).toBe(''); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); diff --git a/packages/aws-amplify-vue/__tests__/GetUser.test.js b/packages/aws-amplify-vue/__tests__/GetUser.test.ts similarity index 68% rename from packages/aws-amplify-vue/__tests__/GetUser.test.js rename to packages/aws-amplify-vue/__tests__/GetUser.test.ts index b0f36b0587e..f64b63b7e93 100644 --- a/packages/aws-amplify-vue/__tests__/GetUser.test.js +++ b/packages/aws-amplify-vue/__tests__/GetUser.test.ts @@ -1,5 +1,5 @@ -import getUser from '../src/services/getUser'; -import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; +import getUser from '@/services/getUser'; +import { Auth } from '../__mocks__/Amplify.mocks'; describe('GetUser Service...', () => { it('...should exist', () => { @@ -7,28 +7,28 @@ describe('GetUser Service...', () => { }); it('...should call Auth.currentAuthenticatedUser', () => { - getUser(AmplifyMocks); - expect(AmplifyMocks.Auth.currentAuthenticatedUser).toBeCalled(); + getUser({ Auth }); + expect(Auth.currentAuthenticatedUser).toBeCalled(); }); it('...should return null if no user', async () => { - const tempMock = Object.assign(AmplifyMocks, { + const tempMock = { Auth: { currentAuthenticatedUser: jest.fn(() => Promise.resolve(null)), }, - }); + }; const res = await getUser(tempMock); expect(res).toEqual(null); }); it('...should returnan error if currentAuthenticatedUser rejects', async () => { - const tempMockFail = Object.assign(AmplifyMocks, { + const tempMockFail = { Auth: { currentAuthenticatedUser: jest.fn(() => Promise.reject(new Error('I rejected')) ), }, - }); + }; const res = await getUser(tempMockFail); expect(res).toBeInstanceOf(Error); }); diff --git a/packages/aws-amplify-vue/__tests__/PhoneField.test.js b/packages/aws-amplify-vue/__tests__/PhoneField.test.ts similarity index 76% rename from packages/aws-amplify-vue/__tests__/PhoneField.test.js rename to packages/aws-amplify-vue/__tests__/PhoneField.test.ts index c9af005731b..524fff237c1 100644 --- a/packages/aws-amplify-vue/__tests__/PhoneField.test.js +++ b/packages/aws-amplify-vue/__tests__/PhoneField.test.ts @@ -1,18 +1,18 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; -import PhoneField from '../src/components/authenticator/PhoneField.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import PhoneField from '@/components/authenticator/PhoneField.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -import countries from '../src/assets/countries'; -/* eslint-enable */ +import countries from '@/assets/countries'; Vue.use(AmplifyPlugin, AmplifyMocks); describe('PhoneField', () => { + let phoneField; let wrapper = null; const mockPhoneNumberChanged = jest.fn(); beforeEach(() => { + phoneField = new PhoneField(); wrapper = shallowMount(PhoneField, { methods: { emitPhoneNumberChanged: mockPhoneNumberChanged, @@ -25,8 +25,8 @@ describe('PhoneField', () => { }); it('sets the correct default data', () => { - expect(typeof PhoneField.data).toBe('function'); - const defaultData = PhoneField.data(); + expect(typeof phoneField.$options.data).toBe('function'); + const defaultData = phoneField.$options.data(); expect(defaultData.countryCode).toEqual('1'); expect(defaultData.local_phone_number).toEqual(''); expect(defaultData.countries).toEqual(countries); diff --git a/packages/aws-amplify-vue/__tests__/PhotoPicker.test.js b/packages/aws-amplify-vue/__tests__/PhotoPicker.test.ts similarity index 88% rename from packages/aws-amplify-vue/__tests__/PhotoPicker.test.js rename to packages/aws-amplify-vue/__tests__/PhotoPicker.test.ts index d2d9e9ef870..27cfde3577a 100644 --- a/packages/aws-amplify-vue/__tests__/PhotoPicker.test.js +++ b/packages/aws-amplify-vue/__tests__/PhotoPicker.test.ts @@ -1,26 +1,31 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount, mount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import PhotoPicker from '../src/components/storage/PhotoPicker.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import PhotoPicker from '@/components/storage/PhotoPicker.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('PhotoPicker', () => { + let photoPicker; + + beforeEach(() => { + photoPicker = new PhotoPicker(); + }); + it('has a mounted hook', () => { - expect(typeof PhotoPicker.mounted).toBe('function'); + expect(photoPicker.$options.mounted.length).toEqual(1); + expect(typeof photoPicker.$options.mounted[0]).toBe('function'); }); it('sets the correct default data', () => { - expect(typeof PhotoPicker.data).toBe('function'); - const defaultData = PhotoPicker.data(); + expect(typeof photoPicker.$options.data).toBe('function'); + const defaultData = photoPicker.$options.data(); expect(defaultData.file).toBe(null); expect(defaultData.s3ImagePath).toEqual(''); expect(defaultData.photoUrl).toEqual(''); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); @@ -142,7 +147,7 @@ describe('PhotoPicker', () => { it('...should call completeFileUpload when upload is clicked', () => { wrapper.vm.upload(); wrapper.vm.file = { foo: 'bar' }; - wrapper.vm.s3ImageFile = 'testImage'; + wrapper.vm.s3ImagePath = 'testImage'; wrapper.vm.$Amplify.Storage.put( 'testPath', { type: 'fakeFile' }, @@ -151,7 +156,7 @@ describe('PhotoPicker', () => { .then(res => { expect(mockCompleteFileUpload).toHaveBeenCalledWith(res.key); expect(wrapper.vm.file).toBe(null); - expect(wrapper.vm.s3ImageFile).toBe(null); + expect(wrapper.vm.s3ImagePath).toBe(null); }) .catch(e => e); }); diff --git a/packages/aws-amplify-vue/__tests__/RequireNewPassword.test.js b/packages/aws-amplify-vue/__tests__/RequireNewPassword.test.ts similarity index 86% rename from packages/aws-amplify-vue/__tests__/RequireNewPassword.test.js rename to packages/aws-amplify-vue/__tests__/RequireNewPassword.test.ts index 7fe5562462a..d83b9fc1f4a 100644 --- a/packages/aws-amplify-vue/__tests__/RequireNewPassword.test.js +++ b/packages/aws-amplify-vue/__tests__/RequireNewPassword.test.ts @@ -1,23 +1,27 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import RequireNewPassword from '../src/components/authenticator/RequireNewPassword.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import RequireNewPassword from '@/components/authenticator/RequireNewPassword.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ + Vue.use(AmplifyPlugin, AmplifyMocks); + describe('RequireNewPassword', () => { - it('has a mounted hook', () => { - expect(typeof RequireNewPassword.mounted).toBe('function'); + let requireNewPassword; + + beforeEach(() => { + requireNewPassword = new RequireNewPassword(); }); + it('sets the correct default data', () => { - expect(typeof RequireNewPassword.data).toBe('function'); - const defaultData = RequireNewPassword.data(); - expect(defaultData.logger).toEqual({}); + expect(typeof requireNewPassword.$options.data).toBe('function'); + const defaultData = requireNewPassword.$options.data(); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); + let wrapper; let header; let testState; @@ -31,7 +35,6 @@ describe('RequireNewPassword', () => { testState = null; }); it('...it should use the amplify plugin with passed modules', () => { - console.log('wrapper', wrapper); expect(wrapper.vm.$Amplify).toBeTruthy(); }); it('...it should be named RequireNewPassword', () => { diff --git a/packages/aws-amplify-vue/__tests__/S3Album.test.js b/packages/aws-amplify-vue/__tests__/S3Album.test.ts similarity index 82% rename from packages/aws-amplify-vue/__tests__/S3Album.test.js rename to packages/aws-amplify-vue/__tests__/S3Album.test.ts index ce71e66d7ac..35e2eb16ddd 100644 --- a/packages/aws-amplify-vue/__tests__/S3Album.test.js +++ b/packages/aws-amplify-vue/__tests__/S3Album.test.ts @@ -1,13 +1,9 @@ -/* eslint-disable */ import Vue from 'vue'; -import { shallowMount, mount } from '@vue/test-utils'; -import * as AmplifyUI from '@aws-amplify/ui'; -import S3Album from '../src/components/storage/S3Album.vue'; -import * as components from '../src/components'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import { shallowMount } from '@vue/test-utils'; +import S3Album from '@/components/storage/S3Album.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); @@ -81,7 +77,7 @@ describe('S3Album', () => { }); it('...should call pushImage when fileUpload event occurs', () => { - AmplifyEventBus.$emit('fileUpload', { foo: 'bar' }); + AmplifyEventBus.$emit('fileUpload', 'randomstring'); expect(mockPushImage).toHaveBeenCalled(); }); }); diff --git a/packages/aws-amplify-vue/__tests__/S3Image.test.js b/packages/aws-amplify-vue/__tests__/S3Image.test.ts similarity index 83% rename from packages/aws-amplify-vue/__tests__/S3Image.test.js rename to packages/aws-amplify-vue/__tests__/S3Image.test.ts index 0c7d534cfb8..bb5c3bc79bf 100644 --- a/packages/aws-amplify-vue/__tests__/S3Image.test.js +++ b/packages/aws-amplify-vue/__tests__/S3Image.test.ts @@ -1,13 +1,8 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount, mount } from '@vue/test-utils'; -import * as AmplifyUI from '@aws-amplify/ui'; -import S3Image from '../src/components/storage/S3Image.vue'; -import * as components from '../src/components'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import S3Image from '@/components/storage/S3Image.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); @@ -19,10 +14,10 @@ describe('S3Image', () => { describe('...when it is mounted with props but methods not mocked...', () => { beforeEach(() => { - global.open = jest.fn(); + window.open = jest.fn(); wrapper = shallowMount(S3Image, { propsData: { - path: 'testPath', + imagePath: 'testPath', }, }); }); @@ -52,14 +47,13 @@ describe('S3Image', () => { }); it('...should call $Amplify.Storage.get when getImages is called with imagePath', () => { - wrapper.vm.imagePath = 'testPath'; wrapper.vm.getImage(); expect(wrapper.vm.$Amplify.Storage.get).toHaveBeenCalled(); }); it('...should not call window.open when blowUp is called', () => { wrapper.vm.blowUp(); - expect(global.open).toHaveBeenCalled(); + expect(window.open).toHaveBeenCalled(); }); }); diff --git a/packages/aws-amplify-vue/__tests__/SetMFA.test.js b/packages/aws-amplify-vue/__tests__/SetMFA.test.ts similarity index 91% rename from packages/aws-amplify-vue/__tests__/SetMFA.test.js rename to packages/aws-amplify-vue/__tests__/SetMFA.test.ts index 54dcbf5956d..d26a17debf9 100644 --- a/packages/aws-amplify-vue/__tests__/SetMFA.test.js +++ b/packages/aws-amplify-vue/__tests__/SetMFA.test.ts @@ -1,26 +1,32 @@ import Vue from 'vue'; -import { shallowMount } from '@vue/test-utils'; // eslint-disable-line -import QrcodeVue from 'qrcode.vue'; // eslint-disable-line -import * as AmplifyUI from '@aws-amplify/ui'; // eslint-disable-line -import SetMFA from '../src/components/authenticator/SetMFA.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import { shallowMount } from '@vue/test-utils'; +import * as AmplifyUI from '@aws-amplify/ui'; +import SetMFA from '@/components/authenticator/SetMFA.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; Vue.use(AmplifyPlugin, AmplifyMocks); describe('SetMFA', () => { + let setMFA; + + beforeEach(() => { + setMFA = new SetMFA(); + }); + it('has a mounted hook', () => { - expect(typeof SetMFA.mounted).toBe('function'); + expect(setMFA.$options.mounted.length).toEqual(1); + expect(typeof setMFA.$options.mounted[0]).toBe('function'); }); it('sets the correct default data', () => { - expect(typeof SetMFA.data).toBe('function'); - const defaultData = SetMFA.data(); + expect(typeof setMFA.$options.data).toBe('function'); + const defaultData = setMFA.$options.data(); expect(defaultData.user).toBe(null); expect(defaultData.mfaPreference).toBe(null); expect(defaultData.token).toBe(''); expect(defaultData.displayTotpSetup).toBe(false); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); @@ -101,7 +107,7 @@ describe('SetMFA', () => { }); }); it('...should call Auth.setupTOTP when setup function is called', async () => { - wrapper.vm.setup(); + await wrapper.vm.setup(); let testToken = `otpauth://totp/AWSCognito:${wrapper.vm.user.username}?secret=gibberish&issuer=AWSCognito`; await expect(wrapper.vm.$Amplify.Auth.setupTOTP).toBeCalledWith( wrapper.vm.user diff --git a/packages/aws-amplify-vue/__tests__/SignIn.test.js b/packages/aws-amplify-vue/__tests__/SignIn.test.ts similarity index 91% rename from packages/aws-amplify-vue/__tests__/SignIn.test.js rename to packages/aws-amplify-vue/__tests__/SignIn.test.ts index 9df2b61d8bf..3e2c3c0d065 100644 --- a/packages/aws-amplify-vue/__tests__/SignIn.test.js +++ b/packages/aws-amplify-vue/__tests__/SignIn.test.ts @@ -1,25 +1,25 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import SignIn from '../src/components/authenticator/SignIn.vue'; -import AmplifyEventBus from '../src/events/AmplifyEventBus'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import SignIn from '@/components/authenticator/SignIn.vue'; +import AmplifyEventBus from '@/events/AmplifyEventBus'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('SignIn', () => { - it('has a mounted hook', () => { - expect(typeof SignIn.mounted).toBe('function'); - }); + let signIn; + + beforeEach(() => { + signIn = new SignIn(); + }); it('sets the correct default data', () => { - expect(typeof SignIn.data).toBe('function'); - const defaultData = SignIn.data(); + expect(typeof signIn.$options.data).toBe('function'); + const defaultData = signIn.$options.data(); expect(defaultData.password).toBe(''); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); diff --git a/packages/aws-amplify-vue/__tests__/SignOut.test.js b/packages/aws-amplify-vue/__tests__/SignOut.test.ts similarity index 87% rename from packages/aws-amplify-vue/__tests__/SignOut.test.js rename to packages/aws-amplify-vue/__tests__/SignOut.test.ts index 9adf3cf14cc..408a6e1d536 100644 --- a/packages/aws-amplify-vue/__tests__/SignOut.test.js +++ b/packages/aws-amplify-vue/__tests__/SignOut.test.ts @@ -1,24 +1,24 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount, mount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import SignOut from '../src/components/authenticator/SignOut.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import SignOut from '@/components/authenticator/SignOut.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('SignOut', () => { - it('has a mounted hook', () => { - expect(typeof SignOut.mounted).toBe('function'); + let signOut; + + beforeEach(() => { + signOut = new SignOut(); }); it('sets the correct default data', () => { - expect(typeof SignOut.data).toBe('function'); - const defaultData = SignOut.data(); + expect(typeof signOut.$options.data).toBe('function'); + const defaultData = signOut.$options.data(); expect(defaultData.show).toBe(false); - expect(defaultData.logger).toEqual({}); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); }); diff --git a/packages/aws-amplify-vue/__tests__/SignUp.test.js b/packages/aws-amplify-vue/__tests__/SignUp.test.ts similarity index 92% rename from packages/aws-amplify-vue/__tests__/SignUp.test.js rename to packages/aws-amplify-vue/__tests__/SignUp.test.ts index 60795f00bec..7fc408bfe57 100644 --- a/packages/aws-amplify-vue/__tests__/SignUp.test.js +++ b/packages/aws-amplify-vue/__tests__/SignUp.test.ts @@ -1,28 +1,25 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; import * as AmplifyUI from '@aws-amplify/ui'; -import SignUp from '../src/components/authenticator/SignUp.vue'; -import PhoneField from '../src/components/authenticator/PhoneField.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import SignUp from '@/components/authenticator/SignUp.vue'; +import PhoneField from '@/components/authenticator/PhoneField.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; +import { signUpWithUsername } from '@/assets/default-sign-up-fields'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -import signUpWithUsername, { - signUpWithEmailFields, - signUpWithPhoneNumberFields, -} from '../src/assets/default-sign-up-fields'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('SignUp', () => { - it('has a mounted hook', () => { - expect(typeof SignUp.mounted).toBe('function'); + let signUp; + + beforeEach(() => { + signUp = new SignUp(); }); it('sets the correct default data', () => { - expect(typeof SignUp.data).toBe('function'); - const defaultData = SignUp.data(); - expect(defaultData.logger).toEqual({}); + expect(typeof signUp.$options.data).toBe('function'); + const defaultData = signUp.$options.data(); + expect(defaultData.logger).toEqual(null); expect(defaultData.error).toEqual(''); expect(defaultData.phoneNumber).toEqual(''); expect(defaultData.defaultSignUpFields).toEqual(signUpWithUsername); diff --git a/packages/aws-amplify-vue/__tests__/SumerianScene.test.js b/packages/aws-amplify-vue/__tests__/SumerianScene.test.ts similarity index 90% rename from packages/aws-amplify-vue/__tests__/SumerianScene.test.js rename to packages/aws-amplify-vue/__tests__/SumerianScene.test.ts index 2b051917ce9..6daf1d9d755 100644 --- a/packages/aws-amplify-vue/__tests__/SumerianScene.test.js +++ b/packages/aws-amplify-vue/__tests__/SumerianScene.test.ts @@ -1,10 +1,8 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; -import SumerianScene from '../src/components/xr/SumerianScene.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import SumerianScene from '@/components/xr/SumerianScene.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); @@ -13,7 +11,7 @@ describe('SumerianScene', () => { describe('mounted with props but methods not mocked...', () => { beforeEach(() => { - global.open = jest.fn(); + window.open = jest.fn(); wrapper = shallowMount(SumerianScene, { propsData: { sceneName: 'testSceneName', diff --git a/packages/aws-amplify-vue/__tests__/UsernameField.test.js b/packages/aws-amplify-vue/__tests__/UsernameField.test.ts similarity index 88% rename from packages/aws-amplify-vue/__tests__/UsernameField.test.js rename to packages/aws-amplify-vue/__tests__/UsernameField.test.ts index 08498915f1d..c5a3f8e6b27 100644 --- a/packages/aws-amplify-vue/__tests__/UsernameField.test.js +++ b/packages/aws-amplify-vue/__tests__/UsernameField.test.ts @@ -1,18 +1,22 @@ -/* eslint-disable */ import Vue from 'vue'; import { shallowMount } from '@vue/test-utils'; -import PhoneField from '../src/components/authenticator/PhoneField.vue'; -import UsernameField from '../src/components/authenticator/UsernameField.vue'; -import AmplifyPlugin from '../src/plugins/AmplifyPlugin'; +import PhoneField from '@/components/authenticator/PhoneField.vue'; +import UsernameField from '@/components/authenticator/UsernameField.vue'; +import AmplifyPlugin from '@/plugins/AmplifyPlugin'; import * as AmplifyMocks from '../__mocks__/Amplify.mocks'; -/* eslint-enable */ Vue.use(AmplifyPlugin, AmplifyMocks); describe('UsernameField', () => { + let usernameField; + + beforeEach(() => { + usernameField = new UsernameField(); + }); + it('sets the correct default data', () => { - expect(typeof UsernameField.data).toBe('function'); - const defaultData = UsernameField.data(); + expect(typeof usernameField.$options.data).toBe('function'); + const defaultData = usernameField.$options.data(); expect(defaultData.username).toEqual(''); expect(defaultData.email).toEqual(''); expect(defaultData.phoneNumberRequired).toEqual(true); diff --git a/packages/aws-amplify-vue/jest.config.js b/packages/aws-amplify-vue/jest.config.js index 780e0138c9c..4d2ebbc5d22 100644 --- a/packages/aws-amplify-vue/jest.config.js +++ b/packages/aws-amplify-vue/jest.config.js @@ -1,20 +1,18 @@ module.exports = { - moduleFileExtensions: ['js', 'jsx', 'json', 'vue'], - transform: { - '^.+\\.vue$': 'vue-jest', - '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': - 'jest-transform-stub', - '^.+\\.jsx?$': 'babel-jest', - }, - moduleNameMapper: { - '^@/(.*)$': '/src/$1', - }, - snapshotSerializers: ['jest-serializer-vue'], - testMatch: [ - '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)', - ], - testURL: 'http://localhost/', - collectCoverage: true, - coverageReporters: ['lcov'], - setupTestFrameworkScriptFile: '/test_setup/setup-jest.ts', + moduleFileExtensions: ['js', 'json', 'vue', 'ts'], + + transform: { + '^.+\\.vue$': 'vue-jest', + '^.+\\.ts$': 'ts-jest', + }, + moduleNameMapper: { + '^@/(.*)$': '/src/$1', + }, + snapshotSerializers: ['jest-serializer-vue'], + testMatch: ['/__tests__/*.test.ts'], + testURL: 'http://localhost/', + testEnvironment: "node", + collectCoverage: true, + coverageReporters: ['lcov'], + setupTestFrameworkScriptFile: '/test_setup/setup-jest.ts', }; diff --git a/packages/aws-amplify-vue/package.json b/packages/aws-amplify-vue/package.json index 9e1d6012ca3..3db8d02c0c0 100644 --- a/packages/aws-amplify-vue/package.json +++ b/packages/aws-amplify-vue/package.json @@ -19,13 +19,21 @@ "vue2-filters": "^0.7.2" }, "devDependencies": { - "@aws-amplify/ui": "1.0.10-unstable.0", + "@aws-amplify/api": "^1.1.3", + "@aws-amplify/auth": "^1.3.3", + "@aws-amplify/core": "^1.1.2", + "@aws-amplify/ui": "^1.0.25", + "@types/jest": "22.2.3", "@vue/cli-plugin-babel": "^3.0.1", + "@vue/cli-plugin-typescript": "^3.11.0", "@vue/cli-plugin-unit-jest": "^3.0.1", "@vue/cli-service": "^3.0.1", "@vue/test-utils": "^1.0.0-beta.20", "babel-core": "7.0.0-bridge.0", + "jest": "22.4.4", "postcss-loader": "^2.1.6", + "ts-jest": "^24.1.0", + "typescript": "^3.6.3", "vue-template-compiler": "^2.5.17" }, "postcss": { @@ -46,4 +54,4 @@ "*.js" ], "main": "./dist/aws-amplify-vue.common.js" -} \ No newline at end of file +} diff --git a/packages/aws-amplify-vue/src/Amplify.vue b/packages/aws-amplify-vue/src/Amplify.vue index 251fd43a9d0..e86543b6e30 100644 --- a/packages/aws-amplify-vue/src/Amplify.vue +++ b/packages/aws-amplify-vue/src/Amplify.vue @@ -2,9 +2,9 @@
- - + \ No newline at end of file +.amplify-album { + width: var(--component-width-desktop); + margin: 1em auto; + border-radius: 6px; + background-color: var(--color-white); + box-shadow: var(--box-shadow); +} +.amplify-album-container { + width: 400px; + margin: 0 auto; + padding: 1em; +} +.amplify-image-container { + display: inline; +} + diff --git a/packages/aws-amplify-vue/src/components/storage/S3Image.vue b/packages/aws-amplify-vue/src/components/storage/S3Image.vue index d6e9d142bd9..139f9bb416f 100644 --- a/packages/aws-amplify-vue/src/components/storage/S3Image.vue +++ b/packages/aws-amplify-vue/src/components/storage/S3Image.vue @@ -21,59 +21,66 @@ - diff --git a/packages/aws-amplify-vue/src/components/storage/index.js b/packages/aws-amplify-vue/src/components/storage/index.ts similarity index 95% rename from packages/aws-amplify-vue/src/components/storage/index.js rename to packages/aws-amplify-vue/src/components/storage/index.ts index 67dcaf486be..6fe28618bd5 100644 --- a/packages/aws-amplify-vue/src/components/storage/index.js +++ b/packages/aws-amplify-vue/src/components/storage/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable */ /* * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * @@ -11,7 +10,6 @@ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions * and limitations under the License. */ -/* eslint-enable */ import Vue from 'vue'; diff --git a/packages/aws-amplify-vue/src/components/xr/SumerianScene.vue b/packages/aws-amplify-vue/src/components/xr/SumerianScene.vue index a50b32fca77..39d024944df 100644 --- a/packages/aws-amplify-vue/src/components/xr/SumerianScene.vue +++ b/packages/aws-amplify-vue/src/components/xr/SumerianScene.vue @@ -140,15 +140,17 @@ - - diff --git a/packages/aws-amplify-vue/src/components/xr/index.js b/packages/aws-amplify-vue/src/components/xr/index.ts similarity index 100% rename from packages/aws-amplify-vue/src/components/xr/index.js rename to packages/aws-amplify-vue/src/components/xr/index.ts diff --git a/packages/aws-amplify-vue/src/events/AmplifyEventBus.js b/packages/aws-amplify-vue/src/events/AmplifyEventBus.ts similarity index 100% rename from packages/aws-amplify-vue/src/events/AmplifyEventBus.js rename to packages/aws-amplify-vue/src/events/AmplifyEventBus.ts diff --git a/packages/aws-amplify-vue/src/plugins/AmplifyPlugin.js b/packages/aws-amplify-vue/src/plugins/AmplifyPlugin.ts similarity index 53% rename from packages/aws-amplify-vue/src/plugins/AmplifyPlugin.js rename to packages/aws-amplify-vue/src/plugins/AmplifyPlugin.ts index ac103ac6537..9fcfee37f85 100644 --- a/packages/aws-amplify-vue/src/plugins/AmplifyPlugin.js +++ b/packages/aws-amplify-vue/src/plugins/AmplifyPlugin.ts @@ -15,26 +15,28 @@ This plugin is a mechanism for avoiding the importation of Amplify into Amplify-Vue, while also making Amplify available to the entire host application. */ + +import Amplify from '@aws-amplify/core'; +import { PluginObject, VueConstructor } from 'vue'; const requiredModules = ['Auth', 'AuthClass', 'I18n', 'Logger']; -const AmplifyPlugin = { - install(Vue, AmplifyModules) { - const missingModules = []; - requiredModules.forEach(r => { - if (!Object.keys(AmplifyModules).includes(r)) { - missingModules.push(r); - } - }); - if (missingModules.length > 0) { - return new Error( - `AmplifyPlugin installation method did not receive required modules: ${missingModules.join( - ', ' - )}.` - ); //eslint-disable-line - } +const AmplifyPlugin: PluginObject = { + install(Vue: VueConstructor, AmplifyModules?: Amplify) { + const missingModules: string[] = []; + const availableModules = Object.keys(AmplifyModules || {}); + requiredModules.forEach(r => { + if (!availableModules.includes(r)) { + missingModules.push(r); + } + }); + if (missingModules.length > 0) { + const label = + 'AmplifyPlugin installation method did not receive required modules'; + return new Error(`${label}: ${missingModules.join(', ')}.`); + } - Vue.prototype.$Amplify = AmplifyModules; - }, + Vue.prototype.$Amplify = AmplifyModules; + }, }; -export default AmplifyPlugin; //eslint-disable-line +export default AmplifyPlugin; diff --git a/packages/aws-amplify-vue/src/services/getUser.js b/packages/aws-amplify-vue/src/services/getUser.ts similarity index 60% rename from packages/aws-amplify-vue/src/services/getUser.js rename to packages/aws-amplify-vue/src/services/getUser.ts index b55af894730..bc7e62496ff 100644 --- a/packages/aws-amplify-vue/src/services/getUser.js +++ b/packages/aws-amplify-vue/src/services/getUser.ts @@ -11,15 +11,20 @@ * and limitations under the License. */ -function GetUser(amplify) { - return amplify.Auth.currentAuthenticatedUser() - .then(user => { - if (!user) { - return null; - } - return user; - }) - .catch(e => new Error(e)); +import { CognitoUser } from 'amazon-cognito-identity-js'; + +interface IAuth { + currentAuthenticatedUser: () => Promise; } -export default GetUser; +export default async function GetUser({ Auth }: { Auth: IAuth }): Promise { + try { + const user = await Auth.currentAuthenticatedUser(); + if (!user) { + return null; + } + return user; + } catch (e) { + return e; + } +} diff --git a/packages/aws-amplify-vue/src/shims-vue.d.ts b/packages/aws-amplify-vue/src/shims-vue.d.ts new file mode 100644 index 00000000000..8f6f4102637 --- /dev/null +++ b/packages/aws-amplify-vue/src/shims-vue.d.ts @@ -0,0 +1,4 @@ +declare module '*.vue' { + import Vue from 'vue'; + export default Vue; +} diff --git a/packages/aws-amplify-vue/test_setup/setup-jest.ts b/packages/aws-amplify-vue/test_setup/setup-jest.ts index 683205ce18a..c860c663c9b 100644 --- a/packages/aws-amplify-vue/test_setup/setup-jest.ts +++ b/packages/aws-amplify-vue/test_setup/setup-jest.ts @@ -1,22 +1,33 @@ window.alert = msg => { - console.log(msg); + // tslint:disable-next-line: no-console + console.log(msg); }; -function noOp() {} +const noOp = () => ({}); if (typeof window.URL.createObjectURL === 'undefined') { - Object.defineProperty(window.URL, 'createObjectURL', { value: noOp }); + Object.defineProperty(window.URL, 'createObjectURL', { value: noOp }); } -class Worker { - constructor(stringUrl) { - this.url = stringUrl; - this.onmessage = () => {}; - } +class FakeWorker implements Worker { + public terminate = Worker.prototype.terminate; + public addEventListener = Worker.prototype.addEventListener; + public removeEventListener = Worker.prototype.removeEventListener; + public dispatchEvent = Worker.prototype.dispatchEvent; + public onerror = Worker.prototype.onerror; + public url: string | URL; - postMessage(msg) { - this.onmessage(msg); - } + constructor(stringUrl: string | URL) { + this.url = stringUrl; + } + + public postMessage(msg: string) { + this.onmessage(msg); + } + + public onmessage(_message: any) { + // Do Nothing + } } -window.Worker = Worker; +window.Worker = FakeWorker; diff --git a/packages/aws-amplify-vue/tsconfig.json b/packages/aws-amplify-vue/tsconfig.json new file mode 100644 index 00000000000..770003e2a66 --- /dev/null +++ b/packages/aws-amplify-vue/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "rootDir": ".", + "outDir": "dist", + "module": "esnext", + "moduleResolution": "node", + "paths": { + "@/*": ["src/*"] + }, + "target": "es5", + "lib": ["dom", "dom.iterable", "es2016"], + "declaration": true, + "allowJs": false, + "strict": true, + "noImplicitThis": true, + "importHelpers": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "stripInternal": true, + "strictNullChecks": false, + "noImplicitAny": false, + "sourceMap": true, + "inlineSources": false, + "skipLibCheck": true + }, + "include": ["src/**/*.js", "src/**/*.ts", "src/**/*.vue"], + "exclude": ["node_modules"] +} diff --git a/packages/aws-amplify-vue/tslint.json b/packages/aws-amplify-vue/tslint.json new file mode 100644 index 00000000000..290fe039c5c --- /dev/null +++ b/packages/aws-amplify-vue/tslint.json @@ -0,0 +1,50 @@ +{ + "defaultSeverity": "warning", + "extends": ["tslint:recommended"], + "linterOptions": { + "exclude": ["node_modules/**"] + }, + "plugins": ["prettier"], + "jsRules": {}, + "rules": { + "prefer-const": true, + "max-line-length": [true, 120], + "no-empty-interface": true, + "no-var-keyword": true, + "no-eval": true, + "space-before-function-paren": [ + true, + { + "anonymous": "never", + "named": "never" + } + ], + "no-parameter-reassignment": true, + "align": [true, "parameters"], + "no-duplicate-imports": true, + "one-variable-per-declaration": [false, "ignore-for-loop"], + "triple-equals": [true, "allow-null-check"], + "indent": [true, "spaces", 2], + "quotemark": [true, "single"], + "whitespace": [ + false, + "check-branch", + "check-decl", + "check-operator", + "check-preblock" + ], + "eofline": true, + "variable-name": [ + true, + "check-format", + "allow-pascal-case", + "allow-snake-case", + "allow-leading-underscore" + ], + "trailing-comma": [false], + "arrow-parens": [false], + "ordered-imports": [false], + "object-literal-sort-keys": [false], + "member-access": [false] + } +} diff --git a/packages/aws-amplify-vue/vue.config.js b/packages/aws-amplify-vue/vue.config.js index b22617da633..73ece9fe6e4 100644 --- a/packages/aws-amplify-vue/vue.config.js +++ b/packages/aws-amplify-vue/vue.config.js @@ -13,7 +13,6 @@ module.exports = { css: { - modules: true, /* ! IMPORTANT ! If css.extract is true (which it is by default), diff --git a/packages/core/src/OAuthHelper/FacebookOAuth.ts b/packages/core/src/OAuthHelper/FacebookOAuth.ts index a424e71214e..bd3626ef8ca 100644 --- a/packages/core/src/OAuthHelper/FacebookOAuth.ts +++ b/packages/core/src/OAuthHelper/FacebookOAuth.ts @@ -13,6 +13,11 @@ import { ConsoleLogger as Logger } from '../Logger'; import JS from '../JS'; +interface RefreshTokenResponse { + token: string; + expires_at: number; +} + const logger = new Logger('CognitoCredentials'); const waitForInit = new Promise((res, rej) => { @@ -58,7 +63,7 @@ export default class FacebookOAuth { return Promise.reject('no fb sdk available'); } - return new Promise((res, rej) => { + return new Promise((res, rej) => { fb.getLoginStatus( fbResponse => { if (!fbResponse || !fbResponse.authResponse) { @@ -76,7 +81,7 @@ export default class FacebookOAuth { logger.debug('the jwtToken is undefined'); rej('the jwtToken is undefined'); } - res({ token: accessToken, expires_at }); + res({ token: accessToken as string, expires_at }); }, { scope: 'public_profile,email' } ); diff --git a/packages/core/src/OAuthHelper/GoogleOAuth.ts b/packages/core/src/OAuthHelper/GoogleOAuth.ts index bcfb7ebeabe..60d08e0f50a 100644 --- a/packages/core/src/OAuthHelper/GoogleOAuth.ts +++ b/packages/core/src/OAuthHelper/GoogleOAuth.ts @@ -13,6 +13,12 @@ import { ConsoleLogger as Logger } from '../Logger'; import JS from '../JS'; +interface RefreshTokenResponse { + token: string; + expires_at: number; + user: any; +} + const logger = new Logger('CognitoCredentials'); const waitForInit = new Promise((res, rej) => { @@ -60,7 +66,7 @@ export default class GoogleOAuth { return Promise.reject('no gapi auth2 available'); } - return new Promise((res, rej) => { + return new Promise((res, rej) => { ga.getAuthInstance() .then(googleAuth => { if (!googleAuth) { @@ -80,7 +86,7 @@ export default class GoogleOAuth { name: profile.getName(), }; - res({ token: id_token, expires_at }); + res({ token: id_token as string, expires_at, user }); }); } else { rej('User is not signed in with Google'); diff --git a/packages/core/src/ServiceWorker/ServiceWorker.ts b/packages/core/src/ServiceWorker/ServiceWorker.ts index 8937930b82a..ef088471cd7 100644 --- a/packages/core/src/ServiceWorker/ServiceWorker.ts +++ b/packages/core/src/ServiceWorker/ServiceWorker.ts @@ -66,11 +66,11 @@ class ServiceWorkerClass { register(filePath: string = '/service-worker.js', scope: string = '/') { this._logger.debug(`registering ${filePath}`); this._logger.debug(`registering service worker with scope ${scope}`); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { if (navigator && 'serviceWorker' in navigator) { navigator.serviceWorker .register(filePath, { - scope: scope, + scope, }) .then(registration => { if (registration.installing) { @@ -111,7 +111,7 @@ class ServiceWorkerClass { enablePush(publicKey: string) { if (!this._registration) throw new Error('Service Worker not registered'); this._publicKey = publicKey; - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { if (JS.browserOrNode().isBrowser) { this._registration.pushManager.getSubscription().then(subscription => { if (subscription) {