From 72243e598378d06394c2b8c59f0ed4b8bc689edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Wed, 13 Oct 2021 08:03:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#55974=20update(cyp?= =?UTF-8?q?ress-dotenv):=20expicit/implicit=20configuration=20support=20by?= =?UTF-8?q?=20@peterblazejewicz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - version 2 bump - maintainer added - implicit and explicit type support for Cypress configuration - return enhanced config based on input and env vars - `env` as optional to count for eary return https://github.com/morficus/cypress-dotenv/blob/master/index.js Thanks! --- types/cypress-dotenv/cypress-dotenv-tests.ts | 37 ++++++++++++++++---- types/cypress-dotenv/index.d.ts | 21 +++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/types/cypress-dotenv/cypress-dotenv-tests.ts b/types/cypress-dotenv/cypress-dotenv-tests.ts index 610b895a89..378984b39f 100644 --- a/types/cypress-dotenv/cypress-dotenv-tests.ts +++ b/types/cypress-dotenv/cypress-dotenv-tests.ts @@ -1,15 +1,38 @@ import dotenvPlugin = require('cypress-dotenv'); -dotenvPlugin({}); - -dotenvPlugin({}, { path: '.env' }); - -dotenvPlugin({}, { path: '.env' }, false); +const cypressConfigExample = { + baseUrl: 'http://example.com', + env: {}, + viewportWidth: 800, + viewportHeight: 600, +}; interface CypressConfiguration { baseUrl: string; port: number; } -// $ExpectType CypressConfiguration -dotenvPlugin({ baseUrl: 'http://example.com', port: 80 }, { path: '.env' }, false); +dotenvPlugin({}); + +dotenvPlugin(cypressConfigExample, { path: '.env' }); + +dotenvPlugin({}, { path: '.env' }, false); + +// takes explicit configuration type + +// $ExpectType EnhancedConfig +let enhancedConfig = dotenvPlugin( + { baseUrl: 'http://example.com', port: 80 }, + { path: '.env' }, + false, +); +enhancedConfig.baseUrl; // $ExpectType string +enhancedConfig.port; // $ExpectType number +enhancedConfig.env?.BASE_URL; + +// takes implicit configuration types +// $ExpectType EnhancedConfig<{ baseUrl: string; port: number; }> +enhancedConfig = dotenvPlugin({ baseUrl: 'http://example.com', port: 80 }, { path: '.env' }); +enhancedConfig.baseUrl; // $ExpectType string +enhancedConfig.port; // $ExpectType number +const url = enhancedConfig.env?.BASE_URL as string; diff --git a/types/cypress-dotenv/index.d.ts b/types/cypress-dotenv/index.d.ts index f602486ae0..8520a09160 100644 --- a/types/cypress-dotenv/index.d.ts +++ b/types/cypress-dotenv/index.d.ts @@ -1,10 +1,25 @@ -// Type definitions for cypress-dotenv 1.2 +// Type definitions for cypress-dotenv 2.0 // Project: https://github.com/morficus/cypress-dotenv // Definitions by: Daiki Ojima +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - import { DotenvConfigOptions } from 'dotenv'; -declare function dotenvPlugin(cypressConfig: T, dotEnvConfig?: DotenvConfigOptions, all?: boolean): T; +// Cypress type +interface CypressConfig { + [key: string]: any; +} + +type EnhancedConfig = T & { + env?: { + [key: string]: unknown; + }; +}; + +declare function dotenvPlugin( + cypressConfig: T, + dotEnvConfig?: DotenvConfigOptions, + all?: boolean, +): EnhancedConfig; export = dotenvPlugin;