Skip to content

Commit

Permalink
💚 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Dec 14, 2023
1 parent 56d473f commit e11f9c5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function makeSavedSessionOptions(opts: SavedSessionOptions): Required<Sav
return {
enabled: true,
maxAge: 86400,
storagePrefix: 'thebe-binder-',
storagePrefix: 'thebe-binder',
...opts,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('config', () => {
expect(config.savedSessions).toEqual({
enabled: true,
maxAge: 86400,
storagePrefix: 'thebe-binder-',
storagePrefix: 'thebe-binder',
});
});
test('server settings', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('options', () => {
expect(makeSavedSessionOptions({})).toEqual({
enabled: true,
maxAge: 86400,
storagePrefix: 'thebe-binder-',
storagePrefix: 'thebe-binder',
});
});
test('overrides', () => {
Expand Down
91 changes: 71 additions & 20 deletions packages/core/tests/url.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, test, expect } from 'vitest';
import { WELL_KNOWN_REPO_PROVIDERS, makeBinderUrls } from '../src/url';
import { makeBinderOptions } from '../src/options';
import type { BinderOptions } from '../src/types';
import { Config } from '../src/config';

const binderUrl = 'https://binder.curvenote.dev/';

Expand All @@ -10,119 +10,170 @@ describe('building binder urls', () => {
test('git', () => {
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'git' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'git' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/HEAD',
launch: 'https://binder.curvenote.dev/v2/git/executablebooks%2Fthebe-binder-base/HEAD',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/HEAD',
});
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'git', ref: 'main' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'git', ref: 'main' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/main',
launch: 'https://binder.curvenote.dev/v2/git/executablebooks%2Fthebe-binder-base/main',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/main',
});
});
test('gitlab', () => {
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'gitlab' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gitlab' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/HEAD',
launch: 'https://binder.curvenote.dev/v2/gl/executablebooks%2Fthebe-binder-base/HEAD',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/HEAD',
});
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'gitlab', ref: 'main' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gitlab', ref: 'main' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/main',
launch: 'https://binder.curvenote.dev/v2/gl/executablebooks%2Fthebe-binder-base/main',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/main',
});
});
test('github', () => {
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'github' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'github' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/HEAD',
launch: 'https://binder.curvenote.dev/v2/gh/executablebooks/thebe-binder-base/HEAD',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/HEAD',
});
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'github', ref: 'main' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'github', ref: 'main' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/main',
launch: 'https://binder.curvenote.dev/v2/gh/executablebooks/thebe-binder-base/main',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/main',
});
});
test('gist', () => {
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'gist' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gist' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/HEAD',
launch: 'https://binder.curvenote.dev/v2/gist/executablebooks/thebe-binder-base/HEAD',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/HEAD',
});
expect(
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'gist', ref: 'main' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gist', ref: 'main' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toEqual({
build: 'https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/main',
launch: 'https://binder.curvenote.dev/v2/gist/executablebooks/thebe-binder-base/main',
storageKey:
'thebe-binder-https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/main',
});
});
});
test('unknown provider throws', () => {
expect(() =>
makeBinderUrls(
makeBinderOptions({ binderUrl, repoProvider: 'unknown' }),
new Config({
binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'unknown' }),
}),
WELL_KNOWN_REPO_PROVIDERS,
),
).toThrow();
});
describe('custom providers', () => {
test('known custom provider - no ref', () => {
const opts = { binderUrl, repoProvider: 'custom', repo: 'sunshine' };
const binderOptions = { binderUrl, repoProvider: 'custom', repo: 'sunshine' };
const c = new Config({ binderOptions });
const spec = {
name: 'custom',
makeUrls: ({ repo, ref }: BinderOptions) => ({
build: `https://custom.host.com/build/custom/${repo}${ref ? `~~~${ref}` : ''}`,
launch: `https://custom.host.com/v2/custom/${repo}${ref ? `~~~${ref}` : ''}`,
makeUrls: (config: Config) => ({
build: `https://custom.host.com/build/custom/${config.binder.repo}`,
launch: `https://custom.host.com/v2/custom/${config.binder.repo}`,
storageKey: `thebe-binder-https://custom.host.com/v2/custom/${config.binder.repo}`,
}),
};
expect(makeBinderUrls(opts, [spec])).toEqual({
expect(makeBinderUrls(c, [spec])).toEqual({
build: `https://custom.host.com/build/custom/sunshine`,
launch: `https://custom.host.com/v2/custom/sunshine`,
storageKey: 'thebe-binder-https://custom.host.com/v2/custom/sunshine',
});
});
test('known custom provider - with ref', () => {
const opts = { binderUrl, repoProvider: 'custom', repo: 'sunshine', ref: 'unicorns' };
const binderOptions = {
binderUrl,
repoProvider: 'custom',
repo: 'sunshine',
ref: 'unicorns',
};
const c = new Config({ binderOptions });
const spec = {
name: 'custom',
makeUrls: ({ repo, ref }: BinderOptions) => ({
build: `https://custom.host.com/build/custom/${repo}${ref ? `~~~${ref}` : ''}`,
launch: `https://custom.host.com/v2/custom/${repo}${ref ? `~~~${ref}` : ''}`,
makeUrls: (config: Config) => ({
build: `https://custom.host.com/build/custom/${config.binder.repo}${
config.binder.ref ? `~~~${config.binder.ref}` : ''
}`,
launch: `https://custom.host.com/v2/custom/${config.binder.repo}${
config.binder.ref ? `~~~${config.binder.ref}` : ''
}`,
storageKey: `thebe-binder-https://custom.host.com/v2/custom/${config.binder.repo}${
config.binder.ref ? `~~~${config.binder.ref}` : ''
}`,
}),
};
expect(makeBinderUrls(opts, [spec])).toEqual({
expect(makeBinderUrls(c, [spec])).toEqual({
build: `https://custom.host.com/build/custom/sunshine~~~unicorns`,
launch: `https://custom.host.com/v2/custom/sunshine~~~unicorns`,
storageKey: 'thebe-binder-https://custom.host.com/v2/custom/sunshine~~~unicorns',
});
});
});
Expand Down

0 comments on commit e11f9c5

Please sign in to comment.