Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions packages/auth-compat/karma.conf.js

This file was deleted.

13 changes: 8 additions & 5 deletions packages/auth-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
"build:release": "yarn build && yarn add-compat-overloads",
"dev": "rollup -c -w",
"test": "run-p --npm-path npm lint test:all",
"test:all": "run-s --npm-path npm test:browser test:node test:integration",
"test:all": "vitest run",
Comment thread
sedanah-m marked this conversation as resolved.
Outdated
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:browser": "karma start",
"test:browser:unit": "karma start --unit",
"test:browser:integration": "karma start --integration",
"test:node": "NODE_OPTIONS='--no-strip-types' ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts",
"test:browser": "vitest run --project=browser",
"test:browser:unit": "vitest run --project=browser",
"test:browser:integration": "vitest run --project=browser test/integration/flows",
"test:browser:debug": "vitest --project=browser --browser.headless=false",
"test:browser:unit:debug": "vitest --project=browser --browser.headless=false",
"test:node": "vitest run --project=node",
Comment thread
sedanah-m marked this conversation as resolved.
Outdated
"test:node:unit": "vitest run --project=node",
"test:node:integration": "NODE_OPTIONS='--no-strip-types' ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --integration",
"test:webdriver": "rollup -c test/integration/webdriver/static/rollup.config.js && NODE_OPTIONS='--no-strip-types' ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --webdriver",
"test:integration": "firebase emulators:exec --project demo-emulatedproject --only auth \"run-s --npm-path npm test:browser:integration test:node:integration test:webdriver\"",
Expand Down
12 changes: 11 additions & 1 deletion packages/auth-compat/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_package_file.js';
import pkg from './package.json' with { type: 'json' };
import tsconfig from './tsconfig.json' with { type: 'json' };

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

const buildPlugins = [json(), resolve(), typescriptPlugin({ typescript })];
const buildPlugins = [
json(),
resolve(),
typescriptPlugin({
typescript,
tsconfigOverride: {
exclude: [...(tsconfig.exclude || []), '**/*.test.ts']
}
})
];

const browserBuilds = [
{
Expand Down
143 changes: 72 additions & 71 deletions packages/auth-compat/src/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
import { FirebaseApp } from '@firebase/app-compat';
import * as exp from '@firebase/auth/internal';
import { Provider } from '@firebase/component';
import { expect, use } from 'chai';
import * as sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { Auth } from './auth';
import { CompatPopupRedirectResolver } from './popup_redirect';
import * as platform from './platform';

vi.mock('./platform', { spy: true });
import {
FAKE_APP_CHECK_CONTROLLER_PROVIDER,
FAKE_HEARTBEAT_CONTROLLER_PROVIDER
} from '../test/helpers/helpers';

use(sinonChai);
} from '../test/helpers/fake_providers';

function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
Expand All @@ -38,45 +35,54 @@ function delay(ms: number): Promise<void> {
// For the most part, the auth methods just call straight through. Some parts
// of the auth compat layer are more complicated: these tests cover those
describe('auth compat', () => {
context('redirect persistence key storage', () => {
let underlyingAuth: exp.AuthImpl;
let app: FirebaseApp;
let providerStub: sinon.SinonStubbedInstance<Provider<'auth'>>;
describe.skipIf(typeof self === 'undefined')(
Comment thread
sedanah-m marked this conversation as resolved.
Outdated
'redirect persistence key storage',
() => {
let underlyingAuth: exp.AuthImpl;
let app: FirebaseApp;
let providerStub: Provider<'auth'>;

beforeEach(() => {
app = { options: { apiKey: 'api-key' } } as FirebaseApp;
underlyingAuth = new exp.AuthImpl(
app,
FAKE_HEARTBEAT_CONTROLLER_PROVIDER,
FAKE_APP_CHECK_CONTROLLER_PROVIDER,
{
apiKey: 'api-key'
} as exp.ConfigInternal
);
sinon.stub(underlyingAuth, '_initializeWithPersistence');
beforeEach(() => {
app = { options: { apiKey: 'api-key' } } as FirebaseApp;
underlyingAuth = new exp.AuthImpl(
app,
FAKE_HEARTBEAT_CONTROLLER_PROVIDER,
FAKE_APP_CHECK_CONTROLLER_PROVIDER,
{
apiKey: 'api-key'
} as exp.ConfigInternal
);
vi.spyOn(
underlyingAuth,
'_initializeWithPersistence'
).mockImplementation(() => Promise.resolve() as any);
Comment thread
sedanah-m marked this conversation as resolved.
Outdated

providerStub = sinon.createStubInstance(Provider);
});
providerStub = {
isInitialized: vi.fn(),
initialize: vi.fn(),
getImmediate: vi.fn(),
get: vi.fn()
} as unknown as Provider<'auth'>;
});

afterEach(() => {
sinon.restore();
});
afterEach(() => {
sessionStorage.clear();
});

it('saves the persistence into session storage if available', async () => {
if (typeof self !== 'undefined') {
underlyingAuth._initializationPromise = Promise.resolve();
sinon.stub(underlyingAuth, '_getPersistenceType').returns('TEST');
sinon
.stub(underlyingAuth, '_initializationPromise')
.value(Promise.resolve());
sinon.stub(
it('saves the persistence into session storage if available', async () => {
vi.spyOn(underlyingAuth, '_getPersistenceType').mockReturnValue('TEST');
Object.defineProperty(underlyingAuth, '_initializationPromise', {
value: Promise.resolve(),
configurable: true
});
vi.spyOn(
exp._getInstance<exp.PopupRedirectResolverInternal>(
CompatPopupRedirectResolver
),
'_openRedirect'
);
providerStub.isInitialized.returns(true);
providerStub.getImmediate.returns(underlyingAuth);
).mockImplementation(async () => {});
(providerStub.isInitialized as any).mockReturnValue(true);
(providerStub.getImmediate as any).mockReturnValue(underlyingAuth);
const authCompat = new Auth(
app,
providerStub as unknown as Provider<'auth'>
Expand All @@ -85,55 +91,52 @@ describe('auth compat', () => {
await authCompat.signInWithRedirect(new exp.GoogleAuthProvider());
expect(
sessionStorage.getItem('firebase:persistence:api-key:undefined')
).to.eq('TEST');
}
});
).toBe('TEST');
});

it('does not save persistence if property throws DOMException', async () => {
if (typeof self !== 'undefined') {
sinon.stub(platform, '_getSelfWindow').returns({
it('does not save persistence if property throws DOMException', async () => {
vi.mocked(platform._getSelfWindow).mockReturnValue({
get sessionStorage(): Storage {
throw new DOMException('Nope!');
}
} as unknown as Window);
const setItemSpy = sinon.spy(sessionStorage, 'setItem');
sinon.stub(underlyingAuth, '_getPersistenceType').returns('TEST');
sinon
.stub(underlyingAuth, '_initializationPromise')
.value(Promise.resolve());
sinon.stub(
const setItemSpy = vi.spyOn(sessionStorage, 'setItem');
vi.spyOn(underlyingAuth, '_getPersistenceType').mockReturnValue('TEST');
Object.defineProperty(underlyingAuth, '_initializationPromise', {
value: Promise.resolve(),
configurable: true
});
vi.spyOn(
exp._getInstance<exp.PopupRedirectResolverInternal>(
CompatPopupRedirectResolver
),
'_openRedirect'
);
providerStub.isInitialized.returns(true);
providerStub.getImmediate.returns(underlyingAuth);
).mockImplementation(async () => {});
Comment thread
sedanah-m marked this conversation as resolved.
Outdated
(providerStub.isInitialized as any).mockReturnValue(true);
(providerStub.getImmediate as any).mockReturnValue(underlyingAuth);
const authCompat = new Auth(
app,
providerStub as unknown as Provider<'auth'>
);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
await authCompat.signInWithRedirect(new exp.GoogleAuthProvider());
await delay(50);
expect(setItemSpy).not.to.have.been.calledWith(
expect(setItemSpy).not.toHaveBeenCalledWith(
'firebase:persistence:api-key:undefined',
'TEST'
);
}
});
});

it('pulls the persistence and sets as the main persistence if set', () => {
if (typeof self !== 'undefined') {
it('pulls the persistence and sets as the main persistence if set', () => {
sessionStorage.setItem(
'firebase:persistence:api-key:undefined',
'none'
);
providerStub.isInitialized.returns(false);
providerStub.initialize.returns(underlyingAuth);
(providerStub.isInitialized as any).mockReturnValue(false);
(providerStub.initialize as any).mockReturnValue(underlyingAuth);
new Auth(app, providerStub as unknown as Provider<'auth'>);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
expect(providerStub.initialize).to.have.been.calledWith({
expect(providerStub.initialize).toHaveBeenCalledWith({
options: {
popupRedirectResolver: CompatPopupRedirectResolver,
persistence: [
Expand All @@ -144,12 +147,10 @@ describe('auth compat', () => {
]
}
});
}
});
});

it('does not die if sessionStorage errors', async () => {
if (typeof self !== 'undefined') {
sinon.stub(platform, '_getSelfWindow').returns({
it('does not die if sessionStorage errors', async () => {
vi.mocked(platform._getSelfWindow).mockReturnValue({
get sessionStorage(): Storage {
throw new DOMException('Nope!');
}
Expand All @@ -158,12 +159,12 @@ describe('auth compat', () => {
'firebase:persistence:api-key:undefined',
'none'
);
providerStub.isInitialized.returns(false);
providerStub.initialize.returns(underlyingAuth);
(providerStub.isInitialized as any).mockReturnValue(false);
(providerStub.initialize as any).mockReturnValue(underlyingAuth);
new Auth(app, providerStub as unknown as Provider<'auth'>);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
await delay(50);
expect(providerStub.initialize).to.have.been.calledWith({
expect(providerStub.initialize).toHaveBeenCalledWith({
options: {
popupRedirectResolver: CompatPopupRedirectResolver,
persistence: [
Expand All @@ -174,7 +175,7 @@ describe('auth compat', () => {
]
}
});
}
});
});
});
}
);
});
Loading
Loading