Skip to content

Commit 49ddb0c

Browse files
committed
v1.2.0 (#123)
* feat(core): support command namespacing with `commandNames` option - #122 * feat(tests): add tests for `commandNames` option - #122 * feat(commands): ability to check auth user from cy command (`cy.getAuthUser`) - #15 * fix(ci): remove duplicate build happening in size check step * chore(tests): add retries to firestore get action test to solve flakiness in CI
1 parent 802f7fe commit 49ddb0c

20 files changed

+1026
-1208
lines changed

.github/workflows/publish.yml

+17-8
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,42 @@ jobs:
1414
- name: Checkout code
1515
uses: actions/checkout@v2
1616

17-
- name: Check package version
18-
uses: technote-space/package-version-check-action@v1
19-
with:
20-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
17+
- name: Check if version has been updated
18+
id: check
19+
uses: EndBug/version-check@v1
2120

2221
- name: Use Node 12
22+
if: steps.check.outputs.changed == 'true'
2323
uses: actions/setup-node@v1
2424
with:
2525
node-version: 12
2626
registry-url: https://registry.npmjs.org/
2727

2828
- name: Get yarn cache
29+
if: steps.check.outputs.changed == 'true'
2930
id: yarn-cache
3031
run: echo "::set-output name=dir::$(yarn cache dir)"
3132

3233
- uses: actions/cache@v1
34+
if: steps.check.outputs.changed == 'true'
3335
with:
3436
path: ${{ steps.yarn-cache.outputs.dir }}
3537
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
3638

3739
- name: Install Dependencies
40+
if: steps.check.outputs.changed == 'true'
3841
env:
3942
CI: true
4043
run: yarn install --frozen-lockfile
4144

4245
- name: Check For Lint
46+
if: steps.check.outputs.changed == 'true'
4347
env:
4448
CI: true
4549
run: yarn lint
4650

4751
- name: Expose Test Environment Variables
52+
if: steps.check.outputs.changed == 'true'
4853
env:
4954
SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
5055
GITHUB_HEAD_REF: ${{ github.head_ref }}
@@ -56,12 +61,14 @@ jobs:
5661
echo "::set-env name=GOOGLE_APPLICATION_CREDENTIALS::$HOME/serviceAccount.json"
5762
5863
- name: Run Unit Tests + Coverage
64+
if: steps.check.outputs.changed == 'true'
5965
env:
6066
CI: true
6167
CODE_CLIMATE: ${{ secrets.CODE_CLIMATE }}
62-
run: yarn test:cov && yarn codecov
68+
run: yarn test:cov
6369

6470
- name: Run Build
71+
if: steps.check.outputs.changed == 'true'
6572
run: yarn build
6673

6774
# Skipped since yarn isn't supported
@@ -73,9 +80,11 @@ jobs:
7380
# github_token: ${{ secrets.GITHUB_TOKEN }}
7481

7582
- name: Size Check
76-
run: yarn size
83+
if: steps.check.outputs.changed == 'true'
84+
run: $(yarn bin)/size-limit
7785

7886
- name: Publish
87+
if: steps.check.outputs.changed == 'true'
7988
env:
8089
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8190
GITHUB_REF: ${{ github.ref }}
@@ -85,14 +94,14 @@ jobs:
8594
npm publish $PUBLISH_FLAG
8695
8796
- name: Archive Build Artifact
97+
if: steps.check.outputs.changed == 'true'
8898
uses: actions/upload-artifact@master
89-
if: success()
9099
with:
91100
name: build
92101
path: lib
93102

94103
- name: Upload Coverage
95-
if: success()
104+
if: steps.check.outputs.changed == 'true'
96105
env:
97106
CI: true
98107
CODE_COV: ${{ secrets.CODE_COV }}

.github/workflows/verify.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
# github_token: ${{ secrets.GITHUB_TOKEN }}
6464

6565
- name: Size Check
66-
run: yarn size
66+
run: $(yarn bin)/size-limit
6767

6868
- name: Upload Coverage
6969
if: success()

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,26 @@ NOTE: You can also use `firebase serve`:
437437
1. Run `firebase login:ci` to generate a CI token for `firebase-tools` (this will give your `cy.callRtdb` and `cy.callFirestore` commands admin access to the DB)
438438
1. Set `FIREBASE_TOKEN` within CI environment variables
439439

440+
### Changing Custom Command Names
441+
442+
Pass `commandNames` in the `options` object to `attachCustomCommands`:
443+
444+
```js
445+
const options = {
446+
// Key is current command name, value is new command name
447+
commandNames: {
448+
login: 'newNameForLogin',
449+
logout: 'newNameForLogout',
450+
callRtdb: 'newNameForCallRtdb',
451+
callFirestore: 'newNameForCallFirestore',
452+
getAuthUser: 'newNameForGetAuthUser',
453+
}
454+
}
455+
attachCustomCommands({ Cypress, cy, firebase }, options);
456+
```
457+
458+
For more information about this feature, please see the [original feature request](https://github.com/prescottprue/cypress-firebase/issues/15).
459+
440460
### Webpack File Preprocessing
441461

442462
If you are using a file preprocessor which is building for the browser environment, such as Webpack, you will need to make sure usage of `fs` is handled since it is used within the cypress-firebase plugin. To do this with webpack, add the following to your config:

examples/basic/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"lint": "eslint src/**.js",
1111
"lint:fix": "yarn lint --fix",
1212
"emulate": "firebase emulators:start --only database,firestore",
13-
"test": "cross-env CYPRESS_baseUrl=http://localhost:3000 cypress run",
14-
"test:open": "cross-env CYPRESS_baseUrl=http://localhost:3000 cypress open",
13+
"test": "cross-env GCLOUD_PROJECT=redux-firebasev3 CYPRESS_baseUrl=http://localhost:3000 cypress run",
14+
"test:open": "cross-env GCLOUD_PROJECT=redux-firebasev3 CYPRESS_baseUrl=http://localhost:3000 cypress open",
1515
"test:emulate": "cross-env FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.database.port)\" FIRESTORE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.firestore.port)\" yarn test:open"
1616
},
1717
"dependencies": {
@@ -22,7 +22,7 @@
2222
},
2323
"devDependencies": {
2424
"cross-env": "^7.0.2",
25-
"cypress": "^4.4.1",
25+
"cypress": "^4.5.0",
2626
"cypress-firebase": "^1.1.0",
2727
"eslint-plugin-chai-friendly": "^0.5.0",
2828
"eslint-plugin-cypress": "^2.10.3",

examples/basic/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -4843,10 +4843,10 @@ cypress-firebase@^1.1.0:
48434843
resolved "https://registry.yarnpkg.com/cypress-firebase/-/cypress-firebase-1.1.0.tgz#87a2dcfedd740270a7b7020982d240ee88f2b922"
48444844
integrity sha512-TWBy7Syi2xWxHswJPP5ys+iGGF1hHOE0b6arnQvMplCrkoj0YUMTe3fpyLiFlYsqYLzczEYTX6gd4aploMI8oA==
48454845

4846-
cypress@^4.4.1:
4847-
version "4.4.1"
4848-
resolved "https://registry.yarnpkg.com/cypress/-/cypress-4.4.1.tgz#f5aa1aa5f328f1299bff328103f7cbad89e80f29"
4849-
integrity sha512-LcskZ/PXRG9XTlEeeenKqz/KddT1x+7O7dqXsdKWPII01LxLNmNHIvHnlUqApchVbinJ5vir6J255CkELSeL0A==
4846+
cypress@^4.5.0:
4847+
version "4.5.0"
4848+
resolved "https://registry.yarnpkg.com/cypress/-/cypress-4.5.0.tgz#01940d085f6429cec3c87d290daa47bb976a7c7b"
4849+
integrity sha512-2A4g5FW5d2fHzq8HKUGAMVTnW6P8nlWYQALiCoGN4bqBLvgwhYM/oG9oKc2CS6LnvgHFiKivKzpm9sfk3uU3zQ==
48504850
dependencies:
48514851
"@cypress/listr-verbose-renderer" "0.4.1"
48524852
"@cypress/request" "2.88.5"

examples/react-redux-firebase/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"eject": "react-scripts eject",
99
"lint": "eslint src/**.js",
1010
"lint:fix": "yarn lint --fix",
11-
"test": "cross-env CYPRESS_baseUrl=http://localhost:3000 cypress run",
12-
"test:open": "cross-env CYPRESS_baseUrl=http://localhost:3000 cypress open",
13-
"test:emulate": "cross-env FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.database.port)\" FIRESTORE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.firestore.port)\" yarn test:open"
11+
"test": "cross-env GCLOUD_PROJECT=redux-firebasev3 CYPRESS_baseUrl=http://localhost:3000 cypress run",
12+
"test:open": "cross-env GCLOUD_PROJECT=redux-firebasev3 CYPRESS_baseUrl=http://localhost:3000 cypress open",
13+
"test:emulate": "cross-env GCLOUD_PROJECT=redux-firebasev3 FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.database.port)\" FIRESTORE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.firestore.port)\" yarn test:open"
1414
},
1515
"dependencies": {
1616
"firebase": "^7.14.1",
@@ -22,7 +22,7 @@
2222
"redux": "^4.0.1"
2323
},
2424
"devDependencies": {
25-
"cross-env": "^5.2.0",
25+
"cross-env": "^7.0.2",
2626
"cypress": "^3.1.5",
2727
"cypress-firebase": "*",
2828
"eslint-plugin-cypress": "^2.10.3",

examples/react-redux-firebase/yarn.lock

+17-1
Original file line numberDiff line numberDiff line change
@@ -4552,13 +4552,20 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
45524552
safe-buffer "^5.0.1"
45534553
sha.js "^2.4.8"
45544554

4555-
cross-env@^5.1.3, cross-env@^5.2.0:
4555+
cross-env@^5.1.3:
45564556
version "5.2.0"
45574557
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.0.tgz#6ecd4c015d5773e614039ee529076669b9d126f2"
45584558
dependencies:
45594559
cross-spawn "^6.0.5"
45604560
is-windows "^1.0.0"
45614561

4562+
cross-env@^7.0.2:
4563+
version "7.0.2"
4564+
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
4565+
integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
4566+
dependencies:
4567+
cross-spawn "^7.0.1"
4568+
45624569
45634570
version "7.0.1"
45644571
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
@@ -4594,6 +4601,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
45944601
shebang-command "^1.2.0"
45954602
which "^1.2.9"
45964603

4604+
cross-spawn@^7.0.1:
4605+
version "7.0.2"
4606+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
4607+
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
4608+
dependencies:
4609+
path-key "^3.1.0"
4610+
shebang-command "^2.0.0"
4611+
which "^2.0.1"
4612+
45974613
45984614
version "2.0.5"
45994615
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8"
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
const fs = require('fs')
2-
const cypressTypeScriptPreprocessor = require('./cy-ts-preprocessor')
32
const cypressFirebasePlugin = require('cypress-firebase').plugin
43

54
module.exports = (on, config) => {
6-
on('file:preprocessor', (file) => {
7-
// console.log(`preprocessor invoked with ${JSON.stringify(file)}`); // uncomment for debugging webpack crashes
8-
return cypressTypeScriptPreprocessor(file).then((results) => {
9-
// console.log(`preprocessor returned ${JSON.stringify(results)}`); // uncomment for debugging webpack crashes
10-
11-
if (!fs.existsSync(file.outputPath)) {
12-
console.error(`Output file does not exist on the filesystem: ${JSON.stringify(file)}`);
13-
throw new Error(`Output file does not exist on the filesystem: ${JSON.stringify(file)}`);
14-
}
15-
return results;
16-
}).catch((err) => {
17-
console.error(`Error occurred running preprocessor`, err);
18-
throw err;
19-
});
20-
})
21-
225
return cypressFirebasePlugin(config)
236
}

examples/typescript/cypress/support/commands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//
2424
// -- This is will overwrite an existing command --
2525
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
26-
import attachCustomCommands from 'cypress-firebase/lib/attachCustomCommands'
26+
import { attachCustomCommands } from 'cypress-firebase'
2727
import * as firebase from 'firebase/app'
2828
import 'firebase/auth'
2929
import 'firebase/database'

examples/typescript/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"scripts": {
66
"start": "react-scripts start",
77
"build": "react-scripts build",
8-
"test": "yarn cypress:run",
9-
"cypress:run": "cypress run",
10-
"cypress:open": "cypress open",
8+
"test": "cross-env GCLOUD_PROJECT=redux-firebasev3 cypress run",
9+
"test:open": "cross-env GCLOUD_PROJECT=redux-firebasev3 cypress open",
1110
"lint": "eslint ./src/*.js cypress/**/*.ts --ext .ts,js",
1211
"lint:fix": "yarn lint --fix"
1312
},
@@ -23,10 +22,11 @@
2322
"devDependencies": {
2423
"@typescript-eslint/eslint-plugin": "^2.29.0",
2524
"@typescript-eslint/parser": "^2.29.0",
26-
"cypress": "^4.4.1",
25+
"cross-env": "^7.0.2",
26+
"cypress": "^4.5.0",
2727
"eslint": "^6.8.0",
2828
"eslint-config-prettier": "^6.11.0",
29-
"eslint-plugin-chai-friendly": "^0.5.0",
29+
"eslint-plugin-chai-friendly": "^0.6.0",
3030
"eslint-plugin-cypress": "^2.10.3",
3131
"eslint-plugin-prettier": "^3.1.3",
3232
"prettier": "^2.0.5",

examples/typescript/yarn.lock

+24-8
Original file line numberDiff line numberDiff line change
@@ -4322,6 +4322,13 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
43224322
safe-buffer "^5.0.1"
43234323
sha.js "^2.4.8"
43244324

4325+
cross-env@^7.0.2:
4326+
version "7.0.2"
4327+
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
4328+
integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
4329+
dependencies:
4330+
cross-spawn "^7.0.1"
4331+
43254332
43264333
version "7.0.1"
43274334
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
@@ -4342,6 +4349,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
43424349
shebang-command "^1.2.0"
43434350
which "^1.2.9"
43444351

4352+
cross-spawn@^7.0.1:
4353+
version "7.0.2"
4354+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
4355+
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
4356+
dependencies:
4357+
path-key "^3.1.0"
4358+
shebang-command "^2.0.0"
4359+
which "^2.0.1"
4360+
43454361
crypto-browserify@^3.11.0:
43464362
version "3.12.0"
43474363
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
@@ -4580,10 +4596,10 @@ cyclist@~0.2.2:
45804596
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-0.2.2.tgz#1b33792e11e914a2fd6d6ed6447464444e5fa640"
45814597
integrity sha1-GzN5LhHpFKL9bW7WRHRkRE5fpkA=
45824598

4583-
cypress@^4.4.1:
4584-
version "4.4.1"
4585-
resolved "https://registry.yarnpkg.com/cypress/-/cypress-4.4.1.tgz#f5aa1aa5f328f1299bff328103f7cbad89e80f29"
4586-
integrity sha512-LcskZ/PXRG9XTlEeeenKqz/KddT1x+7O7dqXsdKWPII01LxLNmNHIvHnlUqApchVbinJ5vir6J255CkELSeL0A==
4599+
cypress@^4.5.0:
4600+
version "4.5.0"
4601+
resolved "https://registry.yarnpkg.com/cypress/-/cypress-4.5.0.tgz#01940d085f6429cec3c87d290daa47bb976a7c7b"
4602+
integrity sha512-2A4g5FW5d2fHzq8HKUGAMVTnW6P8nlWYQALiCoGN4bqBLvgwhYM/oG9oKc2CS6LnvgHFiKivKzpm9sfk3uU3zQ==
45874603
dependencies:
45884604
"@cypress/listr-verbose-renderer" "0.4.1"
45894605
"@cypress/request" "2.88.5"
@@ -5252,10 +5268,10 @@ eslint-module-utils@^2.4.1:
52525268
debug "^2.6.9"
52535269
pkg-dir "^2.0.0"
52545270

5255-
eslint-plugin-chai-friendly@^0.5.0:
5256-
version "0.5.0"
5257-
resolved "https://registry.yarnpkg.com/eslint-plugin-chai-friendly/-/eslint-plugin-chai-friendly-0.5.0.tgz#42418c35c4a83584f3b98449b7b8f4f56205a0a3"
5258-
integrity sha512-Pxe6z8C9fP0pn2X2nGFU/b3GBOCM/5FVus1hsMwJsXP3R7RiXFl7g0ksJbsc0GxiLyidTW4mEFk77qsNn7Tk7g==
5271+
eslint-plugin-chai-friendly@^0.6.0:
5272+
version "0.6.0"
5273+
resolved "https://registry.yarnpkg.com/eslint-plugin-chai-friendly/-/eslint-plugin-chai-friendly-0.6.0.tgz#54052fab79302ed0cea76ab997351ea4809bfb77"
5274+
integrity sha512-Uvvv1gkbRGp/qfN15B0kQyQWg+oFA8buDSqrwmW3egNSk/FpqH2MjQqKOuKwmEL6w4QIQrIjDp+gg6kGGmD3oQ==
52595275

52605276
eslint-plugin-cypress@^2.10.3:
52615277
version "2.10.3"

index.d.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,23 @@ declare module "attachCustomCommands" {
166166
}
167167
}
168168
}
169+
interface CommandNamespacesConfig {
170+
login?: string;
171+
logout?: string;
172+
callRtdb?: string;
173+
callFirestore?: string;
174+
getAuthUser?: string;
175+
}
176+
interface CustomCommandOptions {
177+
commandNames?: CommandNamespacesConfig;
178+
}
169179
/**
170180
* Attach custom commands including cy.login, cy.logout, cy.callRtdb,
171-
* @param commandParams - List of params to provide scope during
181+
* @param context - Context values passed from Cypress environment
172182
* custom command attachment
183+
* @param options - Custom command options
173184
*/
174-
export default function attachCustomCommands(commandParams: AttachCustomCommandParams): void;
185+
export default function attachCustomCommands(context: AttachCustomCommandParams, options?: CustomCommandOptions): void;
175186
}
176187
declare module "extendWithFirebaseConfig" {
177188
export interface CypressEnvironmentOptions {
@@ -274,6 +285,7 @@ declare module "firebase-utils" {
274285
export function deleteCollection(db: any, collectionPath: string, batchSize?: number): Promise<any>;
275286
}
276287
declare module "tasks" {
288+
import * as admin from 'firebase-admin';
277289
import { FixtureData, FirestoreAction, RTDBAction, CallRtdbOptions, CallFirestoreOptions } from "attachCustomCommands";
278290
/**
279291
* @param adminInstance - firebase-admin instance
@@ -301,6 +313,13 @@ declare module "tasks" {
301313
* @returns Promise which resolves with a custom Firebase Auth token
302314
*/
303315
export function createCustomToken(adminInstance: any, uid: string, settings?: any): Promise<string>;
316+
/**
317+
* Get Firebase Auth user based on UID
318+
* @param adminInstance - Admin SDK instance
319+
* @param uid - UID of user for which the custom token will be generated
320+
* @returns Promise which resolves with a custom Firebase Auth token
321+
*/
322+
export function getAuthUser(adminInstance: any, uid: string): Promise<admin.auth.UserRecord>;
304323
}
305324
declare module "plugin" {
306325
import { ExtendedCypressConfig } from "extendWithFirebaseConfig";

0 commit comments

Comments
 (0)