diff --git a/.changeset/odd-terms-talk.md b/.changeset/odd-terms-talk.md new file mode 100644 index 00000000000..4e3036ede9a --- /dev/null +++ b/.changeset/odd-terms-talk.md @@ -0,0 +1,5 @@ +--- +"@aws-amplify/ui-vue": minor +--- + +chore(vue): migrate to standardized tsconfig and align exports test diff --git a/packages/configs/typescript/tsconfig.vue.json b/packages/configs/typescript/tsconfig.vue.json new file mode 100644 index 00000000000..a8743d9f615 --- /dev/null +++ b/packages/configs/typescript/tsconfig.vue.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + // required in `vue` projects + "jsx": "preserve", + // see: https://github.com/vuejs/test-utils/issues/1538 + "skipLibCheck": true, + "types": ["vite/client"] + } +} diff --git a/packages/vue/__mocks__/styleMock.js b/packages/vue/__mocks__/styleMock.js new file mode 100644 index 00000000000..f053ebf7976 --- /dev/null +++ b/packages/vue/__mocks__/styleMock.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/packages/vue/__tests__/exports.spec.ts b/packages/vue/__tests__/exports.spec.ts index 75ac3b112c9..bf50e179811 100644 --- a/packages/vue/__tests__/exports.spec.ts +++ b/packages/vue/__tests__/exports.spec.ts @@ -1,9 +1,10 @@ -import * as exported from '../dist'; +import * as exported from '../src'; describe('@aws-amplify/ui-vue', () => { describe('exports', () => { it('should match snapshot', () => { - expect(Object.keys(exported)).toMatchSnapshot(); + const sortedExports = Object.keys(exported).sort(); + expect(sortedExports).toMatchSnapshot(); }); }); }); diff --git a/packages/vue/index.js b/packages/vue/index.js deleted file mode 100644 index 19181c332f3..00000000000 --- a/packages/vue/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export * from './src/components'; -export * from './src/defaults'; -export * from './src/composables'; diff --git a/packages/vue/jest.config.ts b/packages/vue/jest.config.ts index 1f3bd9a0a29..25f00adc9f9 100644 --- a/packages/vue/jest.config.ts +++ b/packages/vue/jest.config.ts @@ -23,8 +23,11 @@ const config: Config = { }, testEnvironment: 'jsdom', verbose: true, - moduleFileExtensions: ['js', 'ts', 'json', 'vue', 'tsx'], - moduleNameMapper: { '^nanoid$': '/../../node_modules/nanoid' }, + moduleFileExtensions: ['js', 'ts', 'vue'], + moduleNameMapper: { + '\\.css$': '/__mocks__/styleMock.js', + '^nanoid$': '/../../node_modules/nanoid', + }, modulePathIgnorePatterns: ['/dist/'], setupFilesAfterEnv: ['./jest.setup.ts'], transform: { diff --git a/packages/vue/package.json b/packages/vue/package.json index 32fec502a6e..d6c16c2e3d7 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -39,7 +39,6 @@ }, "dependencies": { "@aws-amplify/ui": "6.0.8", - "@vue/tsconfig": "^0.1.3", "@vueuse/core": "7.5.5", "@xstate/vue": "0.8.1", "nanoid": "3.1.31", diff --git a/packages/vue/src/components/__tests__/authenticator.spec.ts b/packages/vue/src/components/__tests__/authenticator.spec.ts index a494d6d751b..fbcc0e80c5e 100644 --- a/packages/vue/src/components/__tests__/authenticator.spec.ts +++ b/packages/vue/src/components/__tests__/authenticator.spec.ts @@ -10,7 +10,7 @@ import { } from '@aws-amplify/ui'; import { components } from '../../../global-spec'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import * as UseAuthComposables from '../../composables/useAuth'; import Authenticator from '../authenticator'; diff --git a/packages/vue/src/components/__tests__/confirm-reset-password.spec.ts b/packages/vue/src/components/__tests__/confirm-reset-password.spec.ts index bcec54c4da5..7ae8582f4e2 100644 --- a/packages/vue/src/components/__tests__/confirm-reset-password.spec.ts +++ b/packages/vue/src/components/__tests__/confirm-reset-password.spec.ts @@ -6,7 +6,7 @@ import { AuthInterpreter, AuthMachineState } from '@aws-amplify/ui'; import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import { UseAuthenticator } from '../../types'; import ConfirmResetPassword from '../confirm-reset-password.vue'; diff --git a/packages/vue/src/components/__tests__/confirm-sign-in.spec.ts b/packages/vue/src/components/__tests__/confirm-sign-in.spec.ts index 123a656b945..5d1cd8fd86e 100644 --- a/packages/vue/src/components/__tests__/confirm-sign-in.spec.ts +++ b/packages/vue/src/components/__tests__/confirm-sign-in.spec.ts @@ -6,7 +6,7 @@ import { AuthInterpreter, AuthMachineState } from '@aws-amplify/ui'; import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import { UseAuthenticator } from '../../types'; import ConfirmSignIn from '../confirm-sign-in.vue'; diff --git a/packages/vue/src/components/__tests__/confirm-sign-up.spec.ts b/packages/vue/src/components/__tests__/confirm-sign-up.spec.ts index 386627779db..f6e8cab9c46 100644 --- a/packages/vue/src/components/__tests__/confirm-sign-up.spec.ts +++ b/packages/vue/src/components/__tests__/confirm-sign-up.spec.ts @@ -10,7 +10,7 @@ import { import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import ConfirmSignUp from '../confirm-sign-up.vue'; jest.spyOn(UseAuthComposables, 'useAuth').mockReturnValue({ diff --git a/packages/vue/src/components/__tests__/confirm-verify-user.spec.ts b/packages/vue/src/components/__tests__/confirm-verify-user.spec.ts index 8c18fbc4220..7336e0e3404 100644 --- a/packages/vue/src/components/__tests__/confirm-verify-user.spec.ts +++ b/packages/vue/src/components/__tests__/confirm-verify-user.spec.ts @@ -10,7 +10,7 @@ import { import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import ConfirmVerifyUser from '../confirm-verify-user.vue'; jest.spyOn(UseAuthComposables, 'useAuth').mockReturnValue({ diff --git a/packages/vue/src/components/__tests__/federated-sign-in-button.spec.ts b/packages/vue/src/components/__tests__/federated-sign-in-button.spec.ts index 9214b3bfea5..be79130ff54 100644 --- a/packages/vue/src/components/__tests__/federated-sign-in-button.spec.ts +++ b/packages/vue/src/components/__tests__/federated-sign-in-button.spec.ts @@ -2,7 +2,7 @@ import { reactive } from 'vue'; import { screen, render, fireEvent } from '@testing-library/vue'; import { components } from '../../../global-spec'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import * as UseAuthComposables from '../../composables/useAuth'; import FederatedSignInButton from '../federated-sign-in-button.vue'; diff --git a/packages/vue/src/components/__tests__/federated-sign-in.spec.ts b/packages/vue/src/components/__tests__/federated-sign-in.spec.ts index f9ae9908cfc..e82af2117e8 100644 --- a/packages/vue/src/components/__tests__/federated-sign-in.spec.ts +++ b/packages/vue/src/components/__tests__/federated-sign-in.spec.ts @@ -2,7 +2,7 @@ import { reactive, ref, Ref } from 'vue'; import { render, screen } from '@testing-library/vue'; import { components } from '../../../global-spec'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import * as UseAuthComposables from '../../composables/useAuth'; import FederatedSignIn from '../federated-sign-in.vue'; diff --git a/packages/vue/src/components/__tests__/force-new-password.spec.ts b/packages/vue/src/components/__tests__/force-new-password.spec.ts index 48ffa1f2775..b9132689bcd 100644 --- a/packages/vue/src/components/__tests__/force-new-password.spec.ts +++ b/packages/vue/src/components/__tests__/force-new-password.spec.ts @@ -6,7 +6,7 @@ import { AuthInterpreter, AuthMachineState } from '@aws-amplify/ui'; import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import { UseAuthenticator } from '../../types'; import ForceNewPassword from '../force-new-password.vue'; diff --git a/packages/vue/src/components/__tests__/forgot-password.spec.ts b/packages/vue/src/components/__tests__/forgot-password.spec.ts index 80865d2ad26..870b49a6cfe 100644 --- a/packages/vue/src/components/__tests__/forgot-password.spec.ts +++ b/packages/vue/src/components/__tests__/forgot-password.spec.ts @@ -6,7 +6,7 @@ import { AuthInterpreter, AuthMachineState } from '@aws-amplify/ui'; import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import { UseAuthenticator } from '../../types'; import ForgotPassword from '../forgot-password.vue'; diff --git a/packages/vue/src/components/__tests__/setup-totp.spec.ts b/packages/vue/src/components/__tests__/setup-totp.spec.ts index 98d05a0ed9e..9f5b6c14271 100644 --- a/packages/vue/src/components/__tests__/setup-totp.spec.ts +++ b/packages/vue/src/components/__tests__/setup-totp.spec.ts @@ -6,7 +6,7 @@ import * as UIModule from '@aws-amplify/ui'; import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import { UseAuthenticator } from '../../types'; import SetupTotp from '../setup-totp.vue'; diff --git a/packages/vue/src/components/__tests__/sign-in.spec.ts b/packages/vue/src/components/__tests__/sign-in.spec.ts index 533aad3acf3..689b02f7ebe 100644 --- a/packages/vue/src/components/__tests__/sign-in.spec.ts +++ b/packages/vue/src/components/__tests__/sign-in.spec.ts @@ -6,7 +6,7 @@ import { AuthInterpreter, AuthMachineState } from '@aws-amplify/ui'; import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import SignIn from '../sign-in.vue'; jest.spyOn(UseAuthComposables, 'useAuth').mockReturnValue({ diff --git a/packages/vue/src/components/__tests__/sign-up.spec.ts b/packages/vue/src/components/__tests__/sign-up.spec.ts index 1cb30e0ca63..db23b7a6388 100644 --- a/packages/vue/src/components/__tests__/sign-up.spec.ts +++ b/packages/vue/src/components/__tests__/sign-up.spec.ts @@ -10,7 +10,7 @@ import { import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import SignUp from '../sign-up.vue'; jest.spyOn(UseAuthComposables, 'useAuth').mockReturnValue({ diff --git a/packages/vue/src/components/__tests__/verify-user.spec.ts b/packages/vue/src/components/__tests__/verify-user.spec.ts index 9b6d3e828d0..bac37bb94fa 100644 --- a/packages/vue/src/components/__tests__/verify-user.spec.ts +++ b/packages/vue/src/components/__tests__/verify-user.spec.ts @@ -11,7 +11,7 @@ import { import { components } from '../../../global-spec'; import * as UseAuthComposables from '../../composables/useAuth'; -import { baseMockServiceFacade } from '../../composables/__mock__/useAuthenticatorMock'; +import { baseMockServiceFacade } from '../../composables/__mocks__/useAuthenticatorMock'; import VerifyUser from '../verify-user.vue'; jest.spyOn(UseAuthComposables, 'useAuth').mockReturnValue({ diff --git a/packages/vue/src/composables/__mock__/useAuthenticatorMock.ts b/packages/vue/src/composables/__mocks__/useAuthenticatorMock.ts similarity index 100% rename from packages/vue/src/composables/__mock__/useAuthenticatorMock.ts rename to packages/vue/src/composables/__mocks__/useAuthenticatorMock.ts diff --git a/packages/vue/tsconfig.json b/packages/vue/tsconfig.json index 87942553075..954c205d19f 100644 --- a/packages/vue/tsconfig.json +++ b/packages/vue/tsconfig.json @@ -1,22 +1,12 @@ { - "compilerOptions": { - "target": "esnext", - "module": "esnext", - "strict": true, - "jsx": "preserve", - "importHelpers": true, - "moduleResolution": "node", - // see: https://github.com/vuejs/test-utils/issues/1538 - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "allowJs": true, - "sourceMap": true, - "baseUrl": ".", - "outDir": "dist", - "resolveJsonModule": true, - "types": ["webpack-env", "vite/client"] - }, - "include": ["jest.setup.ts", "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"], + "extends": "@aws-amplify/typescript-config/tsconfig.vue.json", + "include": [ + "__mocks__", + "__tests__", + "*.ts", + "src/**/*.ts", + "src/**/*.tsx", + "src/**/*.vue" + ], "exclude": ["node_modules"] } diff --git a/packages/vue/vite.config.ts b/packages/vue/vite.config.ts index 52c3f237baf..289bd1cadd9 100644 --- a/packages/vue/vite.config.ts +++ b/packages/vue/vite.config.ts @@ -25,13 +25,7 @@ export default defineConfig({ declaration: true, declarationMap: true, }, - exclude: [ - 'vite.config.ts', - '*.ts', - '__tests__', - '**/__mock__', - '**/__tests__', - ], + exclude: ['*.ts', '**/__mocks__', '**/__tests__'], }, }) as PluginOption, ], @@ -64,11 +58,7 @@ export default defineConfig({ 'aws-amplify/utils', 'vue', ], - output: { - globals: { - vue: 'Vue', - }, - }, + output: { globals: { vue: 'Vue' } }, }, }, }); diff --git a/yarn.lock b/yarn.lock index e567398d4cd..8723d092de6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8711,11 +8711,6 @@ js-beautify "1.14.9" vue-component-type-helpers "1.8.4" -"@vue/tsconfig@^0.1.3": - version "0.1.3" - resolved "https://registry.npmjs.org/@vue/tsconfig/-/tsconfig-0.1.3.tgz#4a61dbd29783d01ddab504276dcf0c2b6988654f" - integrity sha512-kQVsh8yyWPvHpb8gIc9l/HIDiiVUy1amynLNpCy8p+FoCiZXCo6fQos5/097MmnNZc9AtseDsCrfkhqCrJ8Olg== - "@vue/vue3-jest@^29.2.6": version "29.2.6" resolved "https://registry.npmjs.org/@vue/vue3-jest/-/vue3-jest-29.2.6.tgz#2b32c61d99efa4e72a7d1365972dcf43b595b3f0"