Skip to content

Commit 864904e

Browse files
authored
v0.0.7 (#3)
* feat(createTestEnvFile): added styled logger with figures for more clear console messages * feat(deps): added `firebase-tools` as a `peerDependency` (it is needed in order for `callRtdb` to work) * feat(deps): added `firebase-tools-extra` as a `dependency` instead of having it part of install instructions * fix(docs): updated docs to cover simplified install * feat(deps): dev deps updated including `eslint`
1 parent 0e6ba37 commit 864904e

File tree

11 files changed

+4172
-763
lines changed

11 files changed

+4172
-763
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
{
2-
"parser": "babel-eslint",
1+
module.exports = {
2+
parser: "babel-eslint",
33
"extends": "airbnb",
4-
"env": {
5-
"browser": true,
6-
"node": true
4+
env: {
5+
browser: true,
6+
node: true
77
},
8-
"rules": {
8+
rules: {
99
"comma-dangle": [2, "never"],
1010
"no-shadow": 0,
1111
"consistent-return": 0,
@@ -14,7 +14,7 @@
1414
"max-len": 0,
1515
"brace-style": [2, "stroustrup"]
1616
},
17-
"plugins": [
17+
plugins: [
1818
"react"
1919
]
2020
}

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ If you are intereted in what drove the need for this checkout [the why section](
3333

3434
### Setup
3535

36-
1. Install deps `npm i cypress-firebase firebase-tools-extra --save-dev`
36+
1. Make sure you have `firebase-tools` installed (globally or within project). It is used to call to database when using `cy.callRtdb` and `cy.callFirestore`.
37+
1. Install using `npm i cypress-firebase --save-dev`
3738
1. Add the following to the `scripts` section of your `package.json`:
3839

3940
```json
@@ -70,25 +71,31 @@ If you are intereted in what drove the need for this checkout [the why section](
7071
attachCustomCommands({ Cypress, cy, firebase })
7172
```
7273
1. Setup plugin adding following your plugins file (`cypress/plugins/index.js`):
73-
74+
7475
```js
7576
const cypressFirebasePlugin = require('cypress-firebase').plugin
7677

7778
module.exports = (on, config) => {
7879
// `on` is used to hook into various events Cypress emits
7980
// `config` is the resolved Cypress config
80-
81+
8182
// Return extended config (with settings from .firebaserc)
8283
return cypressFirebasePlugin(config)
8384
}
8485
```
85-
86+
8687
The plugin sets `baseUrl` and loads config from `.firebaserc`
8788

8889
### Running
90+
8991
1. Start your local dev server (usually `npm start`) - for faster alternative checkout the [test built version section](#test-built-version)
9092
1. Open cypress test running by running `npm run test:open` in another terminal window
9193

94+
### CI
95+
96+
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)
97+
1. Set `FIREBASE_TOKEN` within CI environment variables
98+
9299
#### Test Built Version
93100

94101
Tests will run faster locally if you tests against the build version of your app instead of your dev version (with hot module reloading and other dev tools). You can do that by:

cmds/createTestEnvFile.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ const pickBy = require('lodash/pickBy');
1010
const size = require('lodash/size');
1111
const keys = require('lodash/keys');
1212
const isUndefined = require('lodash/isUndefined');
13+
const path = require('path');
1314
const envVarBasedOnCIEnv = require('../lib/utils').envVarBasedOnCIEnv;
1415
const getServiceAccount = require('../lib/utils').getServiceAccount;
1516
const getEnvPrefix = require('../lib/utils').getEnvPrefix;
1617
const constants = require('../lib/constants');
17-
const path = require('path');
18+
const logger = require('../lib/logger');
1819

1920
const {
2021
DEFAULT_BASE_PATH,
@@ -40,14 +41,14 @@ function createTestEnvFile() {
4041
if (!uid) {
4142
return Promise.reject(new Error(
4243
`${envPrefix}TEST_UID is missing from environment. Confirm that ${
43-
constants.DEFAULT_TEST_FOLDER_PATH
44+
constants.DEFAULT_TEST_FOLDER_PATH
4445
}/config.json contains either ${envPrefix}TEST_UID or TEST_UID.`
4546
));
4647
}
4748

4849
const FIREBASE_PROJECT_ID = envVarBasedOnCIEnv('FIREBASE_PROJECT_ID');
4950

50-
console.log(`Generating custom auth token for firebase project: ${chalk.cyan(FIREBASE_PROJECT_ID)}\n`); // eslint-disable-line no-console
51+
logger.info(`Generating custom auth token for Firebase project with projectId: ${chalk.cyan(FIREBASE_PROJECT_ID)}`);
5152

5253
// Get service account from local file falling back to environment variables
5354
const serviceAccount = getServiceAccount();
@@ -62,18 +63,15 @@ function createTestEnvFile() {
6263
}
6364

6465
// Get project ID from environment variable
65-
const projectId =
66-
process.env.GCLOUD_PROJECT || envVarBasedOnCIEnv('FIREBASE_PROJECT_ID');
66+
const projectId = process.env.GCLOUD_PROJECT || envVarBasedOnCIEnv('FIREBASE_PROJECT_ID');
6767

6868
// Remove firebase- prefix
6969
const cleanedProjectId = projectId.replace('firebase-', '');
7070

7171
// Handle service account not matching settings in config.json (local)
7272
if (serviceAccount.project_id !== FIREBASE_PROJECT_ID && serviceAccount.project_id !== projectId) {
7373
/* eslint-disable no-console */
74-
console.log(
75-
chalk.yellow(`${fig('⚠')} Warning: project_id "${serviceAccount.project_id}" does not match env var: "${envVarBasedOnCIEnv('FIREBASE_PROJECT_ID')}"`)
76-
);
74+
logger.warn(`project_id "${chalk.cyan(serviceAccount.project_id)}" does not match env var: "${chalk.cyan(envVarBasedOnCIEnv('FIREBASE_PROJECT_ID'))}"`);
7775
/* eslint-enable no-console */
7876
}
7977

@@ -94,8 +92,8 @@ function createTestEnvFile() {
9492
.createCustomToken(uid, { isTesting: true })
9593
.then((customToken) => {
9694
/* eslint-disable no-console */
97-
console.log(
98-
`${chalk.green(fig('✔'))} Custom token generated successfully, writing to ${chalk.cyan(constants.DEFAULT_TEST_ENV_FILE_NAME)}`
95+
logger.success(
96+
`Custom token generated successfully, writing to ${chalk.cyan(constants.DEFAULT_TEST_ENV_FILE_NAME)}`
9997
);
10098
/* eslint-enable no-console */
10199
// Remove firebase app
@@ -119,7 +117,7 @@ function createTestEnvFile() {
119117
// Write config file to cypress.env.json
120118
fs.writeFileSync(testEnvFileFullPath, JSON.stringify(newCypressConfig, null, 2));
121119

122-
console.log(`${chalk.green(fig('✔'))} ${chalk.cyan(constants.DEFAULT_TEST_ENV_FILE_NAME)} updated successfully`); // eslint-disable-line no-console
120+
logger.success(`${chalk.cyan(constants.DEFAULT_TEST_ENV_FILE_NAME)} updated successfully`);
123121

124122
// Create service account file if it does not already exist (for use in reporter)
125123
if (!fs.existsSync(serviceAccountPath)) {
@@ -129,14 +127,14 @@ function createTestEnvFile() {
129127
JSON.stringify(serviceAccount, null, 2)
130128
);
131129

132-
console.log(`${chalk.green(fig('✔'))} ${chalk.cyan('serviceAccount.json')} created successfully`); // eslint-disable-line no-console
130+
logger.success(`${chalk.cyan('serviceAccount.json')} created successfully`);
133131
}
134132
return customToken;
135133
})
136134
.catch((err) => {
137135
/* eslint-disable no-console */
138-
console.error(
139-
`Error generating custom token for uid: ${uid}`,
136+
logger.error(
137+
`Custom token could not be generated for uid: ${chalk.cyan(uid)}`,
140138
err.message || err
141139
);
142140
/* eslint-enable no-console */
@@ -162,7 +160,7 @@ module.exports = function (program) {
162160
.action((directory, options) => createTestEnvFile(options)
163161
.then(() => process.exit(0))
164162
.catch((err) => {
165-
console.log(chalk.red(`Error creating test env file:\n${err.message}`)); // eslint-disable-line no-console
163+
logger.error(`Test env file could not be created:\n${err.message}`);
166164
process.exit(1);
167165
return Promise.reject(err);
168166
}));

0 commit comments

Comments
 (0)