Skip to content

Commit d41f8ab

Browse files
committed
Added a flag to indicate when an emulator state should be saved after shutdown
1 parent 62bd3a6 commit d41f8ab

25 files changed

+7656
-47
lines changed

.firebaserc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
firebase.json
2+
example-app/

cypress.config.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { defineConfig } from "cypress";
2+
import configSetup from "./dist/scripts/config";
23

34
export default defineConfig({
45
component: {
56
devServer: {
67
framework: "react",
78
bundler: "webpack",
89
},
9-
specPattern: "cypress/e2e/**/*.test.tsx"
10+
specPattern: "cypress/e2e/**/*.test.tsx",
11+
},
12+
13+
e2e: {
14+
setupNodeEvents(on, config) {
15+
// implement node event listeners here
16+
return configSetup(on, config);
17+
},
1018
},
1119
});

cypress/e2e/emulator.cy.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
3+
beforeEach(() => {
4+
cy.startEmulator("some-project");
5+
});
6+
7+
it("Should be able to start a session", () => {
8+
cy.session("Some session test example 1111117", () => {
9+
cy.clearAuth("some-project");
10+
cy.addUser(
11+
12+
"somepass",
13+
"some-project",
14+
"predictable-id"
15+
);
16+
cy.visit("http://localhost:3500");
17+
cy.contains("login").click();
18+
cy.window().then((w) => {
19+
cy.waitUntil(() =>
20+
w.document.body.textContent!.includes("[email protected]")
21+
);
22+
});
23+
cy.wait(5000);
24+
});
25+
cy.visit("http://localhost:3500");
26+
cy.contains("[email protected]");
27+
});

cypress/support/commands.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@
3434
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
3535
// }
3636
// }
37-
// }
37+
// }
38+
import { mount } from "cypress/react";
39+
import "../../dist/support/essentials";
40+
41+
import { setEmulatorConfig } from "../../dist/support/emulator";
42+
43+
setEmulatorConfig(require("../../firebase.json"));
44+
45+
cy.mount = mount;

cypress/support/e2e.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
21+

example-app/.env.local

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIREBASE_CONFIG={ "projectId": "some-project", "apiKey": "AIzaSyASb1vcwEf7HmQHVgKtk-Jn0fTwYKIKA0k", "defaultBucket": "gs://some-project.appspot.com", "emulator": true, "appId": "1:359056912148:web:cb9867c5975b12fe72dc01", "measurementId": "G-BWF38SFTM4"}

example-app/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"scripts": {
3+
"start": "env-cmd -f ./.env.local react-start"
4+
},
5+
"dependencies": {
6+
"@muritavo/webpack-microfrontend-scripts": "^0.1.3",
7+
"@onepercentio/one-ui": "^0.11.0",
8+
"@types/react": "^18.0.26",
9+
"@types/react-dom": "^18.0.10",
10+
"env-cmd": "^10.1.0",
11+
"firebase": "^9.15.0",
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0"
14+
},
15+
"devDependencies": {
16+
"typescript": "^4.9.4"
17+
}
18+
}

example-app/public/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>

example-app/src/Login.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
browserLocalPersistence,
3+
User,
4+
signInWithEmailAndPassword,
5+
onAuthStateChanged,
6+
setPersistence,
7+
} from "firebase/auth";
8+
import { useEffect, useMemo, useState } from "react";
9+
import { auth } from "./firebase/firebase.init";
10+
import Skeleton from "@onepercentio/one-ui/dist/components/Skeleton";
11+
12+
export default function Login() {
13+
const [user, setUser] = useState<User | null>();
14+
useEffect(() => {
15+
onAuthStateChanged(auth, (a) => {
16+
setUser(a);
17+
});
18+
}, []);
19+
20+
const content = useMemo(() => {
21+
switch (user) {
22+
case undefined:
23+
return <Skeleton width={10} height={1} />;
24+
case null:
25+
return (
26+
<>
27+
<button
28+
onClick={() =>
29+
signInWithEmailAndPassword(
30+
auth,
31+
32+
"somepass"
33+
)
34+
}
35+
>
36+
login
37+
</button>
38+
</>
39+
);
40+
default:
41+
return <span>Logado como {user.email}</span>;
42+
}
43+
}, [user]);
44+
45+
return (
46+
<>
47+
<p>{localStorage.key(0) || "aspdojsap"}</p>
48+
{content}
49+
</>
50+
);
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG!);
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
initializeFirestore,
3+
connectFirestoreEmulator,
4+
} from "firebase/firestore";
5+
import { initializeApp, setLogLevel } from "firebase/app";
6+
import {
7+
initializeAuth,
8+
connectAuthEmulator,
9+
browserSessionPersistence,
10+
browserPopupRedirectResolver,
11+
browserLocalPersistence,
12+
} from "firebase/auth";
13+
import { getStorage, connectStorageEmulator } from "firebase/storage";
14+
import { getFunctions, connectFunctionsEmulator } from "firebase/functions";
15+
import { getAnalytics } from "firebase/analytics";
16+
import { firebaseConfig } from "./firebase.config";
17+
18+
const { defaultBucket, emulator, ...baseFirebaseConfig } = firebaseConfig;
19+
20+
export const app = initializeApp(baseFirebaseConfig);
21+
export const firestoreInstance = initializeFirestore(app, {
22+
experimentalForceLongPolling: true,
23+
});
24+
export const auth = initializeAuth(app, {
25+
persistence: browserLocalPersistence,
26+
popupRedirectResolver: browserPopupRedirectResolver,
27+
});
28+
export const storageInstance = getStorage(app, defaultBucket);
29+
export const functionsInstance = getFunctions(app);
30+
export const analyticsInstance =
31+
process.env.NODE_ENV === "production" ? getAnalytics(app) : null;
32+
33+
if (emulator) {
34+
setLogLevel("silent");
35+
connectFirestoreEmulator(
36+
firestoreInstance,
37+
`${window.location.hostname}`,
38+
8090
39+
);
40+
connectStorageEmulator(storageInstance, `${window.location.hostname}`, 9199);
41+
connectAuthEmulator(auth, `http://${window.location.hostname}:9099`, {
42+
disableWarnings: true,
43+
});
44+
connectFunctionsEmulator(
45+
functionsInstance,
46+
`${window.location.hostname}`,
47+
5001
48+
);
49+
}

example-app/src/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { render } from "react-dom";
2+
import Login from "./Login";
3+
4+
render(<Login />, document.body);

example-app/tsconfig.json

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig to read more about this file */
4+
5+
/* Projects */
6+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12+
13+
/* Language and Environment */
14+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16+
"jsx": "react-jsx", /* Specify what JSX code is generated. */
17+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26+
27+
/* Modules */
28+
"module": "commonjs", /* Specify what module code is generated. */
29+
// "rootDir": "./", /* Specify the root folder within your source files. */
30+
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
36+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38+
// "resolveJsonModule": true, /* Enable importing .json files. */
39+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
40+
41+
/* JavaScript Support */
42+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
43+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
44+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45+
46+
/* Emit */
47+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
49+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
51+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
52+
// "outDir": "./", /* Specify an output folder for all emitted files. */
53+
// "removeComments": true, /* Disable emitting comments. */
54+
// "noEmit": true, /* Disable emitting files from a compilation. */
55+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
56+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
57+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
58+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
59+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
60+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
61+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
62+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
63+
// "newLine": "crlf", /* Set the newline character for emitting files. */
64+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
65+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
67+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
70+
71+
/* Interop Constraints */
72+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
77+
78+
/* Type Checking */
79+
"strict": true, /* Enable all strict type-checking options. */
80+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
86+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
90+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
96+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
98+
99+
/* Completeness */
100+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
102+
}
103+
}

0 commit comments

Comments
 (0)