diff --git a/e2e/.eslintrc b/e2e/.eslintrc index 7ada225..c3cff65 100644 --- a/e2e/.eslintrc +++ b/e2e/.eslintrc @@ -7,6 +7,7 @@ }, "plugins": [ "@typescript-eslint", + "simple-import-sort", "unicorn", "promise", "prettier", @@ -26,6 +27,28 @@ ], "rules": { "import/order": "error", + "simple-import-sort/imports": ["error", { + "groups": [ + // Node.js builtins. You could also generate this regex if you use a `.js` config. + // For example: `^(${require("module").builtinModules.join("|")})(/|$)` + [ + "^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)", + ], + // Packages. `react` related packages come first. + ["^react", "^@?\\w"], + // Internal packages. + ["^(@|@company|@ui|components|utils|config|vendored-lib)(/.*|$)"], + // Side effect imports. + ["^\\u0000"], + // Parent imports. Put `..` last. + ["^\\.\\.(?!/?$)", "^\\.\\./?$"], + // Other relative imports. Put same-folder imports and `.` last. + ["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"], + // Style imports. + ["^.+\\.s?css$"] + ] + }], + "simple-import-sort/exports": "error", "node/no-unsupported-features/es-syntax": "off", "node/no-unpublished-import": "off", "unicorn/numeric-separators-style": "off", diff --git a/e2e/helpers/authorization-endpoint.ts b/e2e/helpers/authorization-endpoint.ts index ba1ce19..58a7690 100644 --- a/e2e/helpers/authorization-endpoint.ts +++ b/e2e/helpers/authorization-endpoint.ts @@ -1,5 +1,7 @@ import * as querystring from 'querystring'; + import { Page } from 'playwright-chromium'; + import { User } from '../types'; export default async ( diff --git a/e2e/helpers/grants.ts b/e2e/helpers/grants.ts index adf2d5f..ac395ea 100644 --- a/e2e/helpers/grants.ts +++ b/e2e/helpers/grants.ts @@ -1,4 +1,5 @@ import { Page } from 'playwright-chromium'; + import { User } from '../types'; export default async (page: Page, user: User): Promise => { diff --git a/e2e/helpers/index.ts b/e2e/helpers/index.ts index 5e1095a..fedf5ea 100644 --- a/e2e/helpers/index.ts +++ b/e2e/helpers/index.ts @@ -1,7 +1,5 @@ -import authorizationEndpoint from './authorization-endpoint'; -import grants from './grants'; -import introspectEndpoint from './introspect-endpoint'; -import tokenEndpoint from './token-endpoint'; -import userInfoEndpoint from './user-info-endpoint'; - -export { authorizationEndpoint, introspectEndpoint, grants, tokenEndpoint, userInfoEndpoint }; +export { default as authorizationEndpoint } from './authorization-endpoint'; +export { default as grants } from './grants'; +export { default as introspectEndpoint } from './introspect-endpoint'; +export { default as tokenEndpoint } from './token-endpoint'; +export { default as userInfoEndpoint } from './user-info-endpoint'; diff --git a/e2e/helpers/introspect-endpoint.ts b/e2e/helpers/introspect-endpoint.ts index ce5e650..16191c0 100644 --- a/e2e/helpers/introspect-endpoint.ts +++ b/e2e/helpers/introspect-endpoint.ts @@ -1,5 +1,7 @@ import * as querystring from 'querystring'; + import axios, { AxiosRequestConfig } from 'axios'; + import apiResources from '../config/api-resources.json'; export default async ( diff --git a/e2e/helpers/token-endpoint.ts b/e2e/helpers/token-endpoint.ts index 0486a7b..e4f6404 100644 --- a/e2e/helpers/token-endpoint.ts +++ b/e2e/helpers/token-endpoint.ts @@ -1,4 +1,5 @@ import * as querystring from 'querystring'; + import axios from 'axios'; import { decode as decodeJWT } from 'jws'; diff --git a/e2e/package-lock.json b/e2e/package-lock.json index 36a2312..46dea5b 100644 --- a/e2e/package-lock.json +++ b/e2e/package-lock.json @@ -32,6 +32,7 @@ "eslint-plugin-node": "11.1.0", "eslint-plugin-prettier": "4.0.0", "eslint-plugin-promise": "5.1.1", + "eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-unicorn": "39.0.0", "husky": "7.0.4", "jest": "27.4.0", @@ -3107,6 +3108,15 @@ "eslint": "^7.0.0" } }, + "node_modules/eslint-plugin-simple-import-sort": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz", + "integrity": "sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw==", + "dev": true, + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-plugin-unicorn": { "version": "39.0.0", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-39.0.0.tgz", @@ -11015,6 +11025,13 @@ "dev": true, "requires": {} }, + "eslint-plugin-simple-import-sort": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz", + "integrity": "sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw==", + "dev": true, + "requires": {} + }, "eslint-plugin-unicorn": { "version": "39.0.0", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-39.0.0.tgz", diff --git a/e2e/package.json b/e2e/package.json index 6101a0b..fd72bb4 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -34,6 +34,7 @@ "eslint-plugin-node": "11.1.0", "eslint-plugin-prettier": "4.0.0", "eslint-plugin-promise": "5.1.1", + "eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-unicorn": "39.0.0", "husky": "7.0.4", "jest": "27.4.0", diff --git a/e2e/tests/base-path.spec.ts b/e2e/tests/base-path.spec.ts index 563ba1c..5a4f318 100644 --- a/e2e/tests/base-path.spec.ts +++ b/e2e/tests/base-path.spec.ts @@ -1,6 +1,7 @@ import * as querystring from 'querystring'; -import * as dotenv from 'dotenv'; + import axios from 'axios'; +import * as dotenv from 'dotenv'; import clients from '../config/clients-configuration.json'; import type { Client } from '../types'; diff --git a/e2e/tests/custom-endpoints/user-management.spec.ts b/e2e/tests/custom-endpoints/user-management.spec.ts index 26fd5d6..48d8166 100644 --- a/e2e/tests/custom-endpoints/user-management.spec.ts +++ b/e2e/tests/custom-endpoints/user-management.spec.ts @@ -1,11 +1,10 @@ -import * as dotenv from 'dotenv'; - import axios from 'axios'; import Chance from 'chance'; -import { Client, User } from '../../types'; +import * as dotenv from 'dotenv'; import clients from '../../config/clients-configuration.json'; import { introspectEndpoint, tokenEndpoint, userInfoEndpoint } from '../../helpers'; +import { Client, User } from '../../types'; describe('User management', () => { const chance = new Chance(); diff --git a/e2e/tests/flows/authorization-code-pkce.e2e-spec.ts b/e2e/tests/flows/authorization-code-pkce.e2e-spec.ts index e1d7a4f..84e17f3 100644 --- a/e2e/tests/flows/authorization-code-pkce.e2e-spec.ts +++ b/e2e/tests/flows/authorization-code-pkce.e2e-spec.ts @@ -1,11 +1,12 @@ import * as crypto from 'crypto'; + import * as dotenv from 'dotenv'; -import { chromium, Page, Browser } from 'playwright-chromium'; +import { Browser, chromium, Page } from 'playwright-chromium'; -import type { User, Client } from '../../types'; -import users from '../../config/user-configuration.json'; import clients from '../../config/clients-configuration.json'; +import users from '../../config/user-configuration.json'; import { authorizationEndpoint, introspectEndpoint, tokenEndpoint, userInfoEndpoint } from '../../helpers'; +import type { Client, User } from '../../types'; const testCases: User[] = users .map(u => ({ diff --git a/e2e/tests/flows/authorization-code.e2e-spec.ts b/e2e/tests/flows/authorization-code.e2e-spec.ts index 83ad1b6..44b9c65 100644 --- a/e2e/tests/flows/authorization-code.e2e-spec.ts +++ b/e2e/tests/flows/authorization-code.e2e-spec.ts @@ -1,10 +1,10 @@ import * as dotenv from 'dotenv'; -import { chromium, Page, Browser } from 'playwright-chromium'; +import { Browser, chromium, Page } from 'playwright-chromium'; -import type { User, Client } from '../../types'; -import users from '../../config/user-configuration.json'; import clients from '../../config/clients-configuration.json'; +import users from '../../config/user-configuration.json'; import { authorizationEndpoint, introspectEndpoint, tokenEndpoint, userInfoEndpoint } from '../../helpers'; +import type { Client, User } from '../../types'; const testCases: User[] = users .map(u => ({ diff --git a/e2e/tests/flows/client-credentials-flow.spec.ts b/e2e/tests/flows/client-credentials-flow.spec.ts index 165cb35..db3e064 100644 --- a/e2e/tests/flows/client-credentials-flow.spec.ts +++ b/e2e/tests/flows/client-credentials-flow.spec.ts @@ -1,8 +1,8 @@ import * as dotenv from 'dotenv'; import clients from '../../config/clients-configuration.json'; -import type { Client } from '../../types'; import { introspectEndpoint, tokenEndpoint } from '../../helpers'; +import type { Client } from '../../types'; describe('Client Credentials Flow', () => { let client: Client; diff --git a/e2e/tests/flows/implicit-flow.e2e-spec.ts b/e2e/tests/flows/implicit-flow.e2e-spec.ts index 4114c31..6b2e6f8 100644 --- a/e2e/tests/flows/implicit-flow.e2e-spec.ts +++ b/e2e/tests/flows/implicit-flow.e2e-spec.ts @@ -1,12 +1,13 @@ import * as querystring from 'querystring'; + import * as dotenv from 'dotenv'; import { decode as decodeJWT } from 'jws'; -import { chromium, Page, Browser } from 'playwright-chromium'; +import { Browser, chromium, Page } from 'playwright-chromium'; -import type { User, Client } from '../../types'; -import users from '../../config/user-configuration.json'; import clients from '../../config/clients-configuration.json'; +import users from '../../config/user-configuration.json'; import { authorizationEndpoint, introspectEndpoint, userInfoEndpoint } from '../../helpers'; +import type { Client, User } from '../../types'; const testCases: User[] = users .map(u => ({ @@ -59,7 +60,7 @@ describe('Implicit Flow', () => { const query = querystring.parse(hash); const tokenParameter = query['access_token']; - expect(typeof tokenParameter).toEqual('string'); + expect(typeof tokenParameter).toBe('string'); token = tokenParameter as string; const decodedAccessToken = decodeJWT(token); expect(decodedAccessToken).toMatchSnapshot(); @@ -87,7 +88,7 @@ describe('Implicit Flow', () => { const query = querystring.parse(hash); const tokenParameter = query['id_token']; - expect(typeof tokenParameter).toEqual('string'); + expect(typeof tokenParameter).toBe('string'); token = tokenParameter as string; const decodedAccessToken = decodeJWT(token); expect(decodedAccessToken).toMatchSnapshot(); diff --git a/e2e/tests/flows/password-flow.spec.ts b/e2e/tests/flows/password-flow.spec.ts index 29d37d2..c7e4e63 100644 --- a/e2e/tests/flows/password-flow.spec.ts +++ b/e2e/tests/flows/password-flow.spec.ts @@ -1,9 +1,9 @@ import * as dotenv from 'dotenv'; -import users from '../../config/user-configuration.json'; import clients from '../../config/clients-configuration.json'; -import type { Client, User } from '../../types'; +import users from '../../config/user-configuration.json'; import { introspectEndpoint, tokenEndpoint, userInfoEndpoint } from '../../helpers'; +import type { Client, User } from '../../types'; const testCases: User[] = users .map(u => ({ diff --git a/e2e/tests/https.spec.ts b/e2e/tests/https.spec.ts index b61ccaa..228a699 100644 --- a/e2e/tests/https.spec.ts +++ b/e2e/tests/https.spec.ts @@ -1,6 +1,7 @@ import { Agent } from 'https'; -import * as dotenv from 'dotenv'; + import axios from 'axios'; +import * as dotenv from 'dotenv'; describe('Https', () => { beforeAll(() => { diff --git a/e2e/types/index.ts b/e2e/types/index.ts index 13c466b..881335e 100644 --- a/e2e/types/index.ts +++ b/e2e/types/index.ts @@ -1,6 +1,4 @@ -import Claim from './claim'; -import ApiResource from './api-resource'; -import Client from './client'; -import User from './user'; - -export { ApiResource, Claim, Client, User }; +export { default as ApiResource } from './api-resource'; +export { default as Claim } from './claim'; +export { default as Client } from './client'; +export { default as User } from './user';