-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: hermione -> testplane #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,68 @@ | ||
import { EventEmitter } from "events"; | ||
|
||
import type Hermione from "hermione"; | ||
import type Testplane from "testplane"; | ||
import type { Config } from "testplane"; | ||
|
||
import plugin from "./"; | ||
import * as readToken from "./read-token"; | ||
|
||
type BrowserConfig = Config["browsers"][string]; | ||
|
||
jest.mock("./config", () => ({ parseConfig: jest.fn(opts => opts) })); | ||
|
||
jest.mock("./read-token"); | ||
const readTokenMock = readToken as jest.Mocked<typeof readToken>; | ||
|
||
describe("hermione-oauth", () => { | ||
const browser = (config: object = {}): Hermione.BrowserConfig => config as unknown as Hermione.BrowserConfig; | ||
describe("@testplane/oauth", () => { | ||
const browser = (config: object = {}): BrowserConfig => config as unknown as BrowserConfig; | ||
|
||
const hermioneMock = (browsers: Record<string, Hermione.BrowserConfig>): Hermione => { | ||
const emitter = new EventEmitter() as unknown as Hermione; | ||
const testplaneMock = (browsers: Record<string, BrowserConfig>): Testplane => { | ||
const emitter = new EventEmitter() as any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you decide to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because later we are trying to set some properties of emitter. And we can't do that since hermione@8: those are readonly:
|
||
|
||
emitter.events = { BEGIN: "begin" } as Hermione.EVENTS; | ||
emitter.events = { BEGIN: "begin" } | ||
emitter.config = { | ||
forBrowser: (id: string) => browsers[id], | ||
getBrowserIds: () => Object.keys(browsers), | ||
} as Hermione.Config; | ||
} as Config; | ||
|
||
return emitter; | ||
}; | ||
|
||
test("should do nothing if plugin is disabled", () => { | ||
const config = { headers: { "<foo>": "<bar>" } }; | ||
const hermione = hermioneMock({ "<bro-id>": browser(config) }); | ||
const testplane = testplaneMock({ "<bro-id>": browser(config) }); | ||
|
||
plugin(hermione, { enabled: false }); | ||
hermione.emit(hermione.events.BEGIN); | ||
plugin(testplane, { enabled: false }); | ||
testplane.emit(testplane.events.BEGIN); | ||
|
||
expect(config).toEqual({ headers: { "<foo>": "<bar>" } }); | ||
}); | ||
|
||
test("should set token for each browser config", () => { | ||
const [config1, config2] = [{ headers: { "<foo>": "<bar>" } }, { headers: { "<baz>": "<quux>" } }]; | ||
const hermione = hermioneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) }); | ||
const testplane = testplaneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) }); | ||
|
||
plugin(hermione, { enabled: true, token: "123456789" }); | ||
hermione.emit(hermione.events.BEGIN); | ||
plugin(testplane, { enabled: true, token: "123456789" }); | ||
testplane.emit(testplane.events.BEGIN); | ||
|
||
expect(config1).toEqual({ headers: { "<foo>": "<bar>", Authorization: "OAuth 123456789" } }); | ||
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 123456789" } }); | ||
}); | ||
|
||
test("should not set token if authorization header is already set", () => { | ||
const config = { headers: { Authorization: "<foo>" } }; | ||
const hermione = hermioneMock({ "<bro-id>": browser(config) }); | ||
const testplane = testplaneMock({ "<bro-id>": browser(config) }); | ||
|
||
plugin(hermione, { enabled: true, token: "123456789" }); | ||
hermione.emit(hermione.events.BEGIN); | ||
plugin(testplane, { enabled: true, token: "123456789" }); | ||
testplane.emit(testplane.events.BEGIN); | ||
|
||
expect(config).toEqual({ headers: { Authorization: "<foo>" } }); | ||
}); | ||
|
||
test("should read token from file when it is given as absolute path", () => { | ||
const hermione = hermioneMock({ "<bro-id>": browser() }); | ||
const testplane = testplaneMock({ "<bro-id>": browser() }); | ||
|
||
plugin(hermione, { enabled: true, token: "/foo/bar", help: "https://<help>" }); | ||
plugin(testplane, { enabled: true, token: "/foo/bar", help: "https://<help>" }); | ||
|
||
expect(readTokenMock.default).toHaveBeenCalledTimes(1); | ||
expect(readTokenMock.default).toHaveBeenCalledWith("/foo/bar", "https://<help>"); | ||
|
@@ -69,10 +72,10 @@ describe("hermione-oauth", () => { | |
readTokenMock.default.mockReturnValue("987654321"); | ||
|
||
const [config1, config2] = [{ headers: { "<foo>": "<bar>" } }, { headers: { "<baz>": "<quux>" } }]; | ||
const hermione = hermioneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) }); | ||
const testplane = testplaneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) }); | ||
|
||
plugin(hermione, { enabled: true, token: "/foo/bar" }); | ||
hermione.emit(hermione.events.BEGIN); | ||
plugin(testplane, { enabled: true, token: "/foo/bar" }); | ||
testplane.emit(testplane.events.BEGIN); | ||
|
||
expect(config1).toEqual({ headers: { "<foo>": "<bar>", Authorization: "OAuth 987654321" } }); | ||
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 987654321" } }); | ||
|
@@ -82,11 +85,11 @@ describe("hermione-oauth", () => { | |
readTokenMock.default.mockReturnValue("987654321"); | ||
|
||
const config = { headers: { Authorization: "<foo>" } }; | ||
const hermione = hermioneMock({ "<bro-id>": browser(config) }); | ||
const testplane = testplaneMock({ "<bro-id>": browser(config) }); | ||
|
||
plugin(hermione, { enabled: true, token: "/foo/bar" }); | ||
plugin(testplane, { enabled: true, token: "/foo/bar" }); | ||
|
||
hermione.emit(hermione.events.BEGIN); | ||
testplane.emit(testplane.events.BEGIN); | ||
|
||
expect(config).toEqual({ headers: { Authorization: "<foo>" } }); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
1.0.0
?