@aurelia/storybook 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +31 -3
- package/__tests__/preset.test.ts +49 -0
- package/__tests__/preview.test.ts +139 -0
- package/__tests__/render.test.ts +0 -1
- package/__tests__/webpack.test.ts +21 -0
- package/apps/hello-world/.storybook/main.ts +30 -0
- package/apps/hello-world/.storybook/preview.ts +1 -0
- package/apps/hello-world/.stylelintrc.json +5 -0
- package/apps/hello-world/.yarnrc.yml +2 -0
- package/apps/hello-world/README.md +28 -0
- package/apps/hello-world/eslint.config.mjs +25 -0
- package/apps/hello-world/favicon.ico +0 -0
- package/apps/hello-world/index.html +17 -0
- package/apps/hello-world/package.json +65 -0
- package/apps/hello-world/src/hello-world.html +6 -0
- package/apps/hello-world/src/hello-world.ts +17 -0
- package/apps/hello-world/src/main.ts +6 -0
- package/apps/hello-world/src/my-app.html +1 -0
- package/apps/hello-world/src/my-app.ts +3 -0
- package/apps/hello-world/src/resource.d.ts +15 -0
- package/apps/hello-world/src/stories/hello-world.stories.ts +53 -0
- package/apps/hello-world/test/my-app.spec.ts +15 -0
- package/apps/hello-world/test/setup.ts +29 -0
- package/apps/hello-world/tsconfig.json +18 -0
- package/apps/hello-world/tsconfig.vitest.json +11 -0
- package/apps/hello-world/vite.config.ts +19 -0
- package/apps/hello-world/vitest.config.ts +15 -0
- package/apps/hello-world-webpack/.storybook/main.ts +18 -0
- package/apps/hello-world-webpack/.storybook/preview.ts +3 -0
- package/apps/hello-world-webpack/.stylelintrc.json +5 -0
- package/apps/hello-world-webpack/.yarnrc.yml +2 -0
- package/apps/hello-world-webpack/README.md +29 -0
- package/apps/hello-world-webpack/eslint.config.mjs +25 -0
- package/apps/hello-world-webpack/favicon.ico +0 -0
- package/apps/hello-world-webpack/index.html +15 -0
- package/apps/hello-world-webpack/package-lock.json +10178 -0
- package/apps/hello-world-webpack/package.json +55 -0
- package/apps/hello-world-webpack/src/main.ts +6 -0
- package/apps/hello-world-webpack/src/my-app.css +3 -0
- package/apps/hello-world-webpack/src/my-app.html +1 -0
- package/apps/hello-world-webpack/src/my-app.stories.ts +12 -0
- package/apps/hello-world-webpack/src/my-app.ts +3 -0
- package/apps/hello-world-webpack/src/resource.d.ts +13 -0
- package/apps/hello-world-webpack/tsconfig.json +18 -0
- package/apps/hello-world-webpack/webpack.config.js +111 -0
- package/dist/index.js +112 -3
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +109 -0
- package/dist/index.mjs.map +1 -0
- package/dist/preset.js +44 -2
- package/dist/preset.js.map +1 -0
- package/dist/preset.mjs +46 -0
- package/dist/preset.mjs.map +1 -0
- package/dist/preview/render.js +26 -14
- package/dist/preview/render.js.map +1 -0
- package/dist/{src/preview/render.js → preview/render.mjs} +8 -4
- package/dist/preview/render.mjs.map +1 -0
- package/dist/preview/types.js +3 -1
- package/dist/preview/types.js.map +1 -0
- package/dist/preview/types.mjs +2 -0
- package/dist/preview/types.mjs.map +1 -0
- package/dist/preview.js +75 -0
- package/dist/preview.js.map +1 -0
- package/dist/preview.mjs +73 -0
- package/dist/preview.mjs.map +1 -0
- package/dist/webpack.js +23 -0
- package/dist/webpack.js.map +1 -0
- package/dist/webpack.mjs +21 -0
- package/dist/webpack.mjs.map +1 -0
- package/jest.config.js +1 -1
- package/package.json +40 -20
- package/rollup.config.mjs +51 -0
- package/src/preset.ts +22 -5
- package/src/preview.ts +50 -0
- package/src/webpack.ts +21 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +1 -0
- package/dist/__tests__/example.test.js +0 -6
- package/dist/__tests__/render.test.d.ts +0 -1
- package/dist/__tests__/render.test.js +0 -156
- package/dist/index.d.ts +0 -3
- package/dist/preset.d.ts +0 -8
- package/dist/preview/render.d.ts +0 -17
- package/dist/preview/render.test.d.ts +0 -1
- package/dist/preview/render.test.js +0 -126
- package/dist/preview/types.d.ts +0 -5
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -3
- package/dist/src/preset.d.ts +0 -8
- package/dist/src/preset.js +0 -11
- package/dist/src/preview/render.d.ts +0 -17
- package/dist/src/preview/types.d.ts +0 -5
- package/dist/src/preview/types.js +0 -1
- /package/{dist/__tests__/example.test.d.ts → apps/hello-world-webpack/.env.development} +0 -0
package/src/preview.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { renderToCanvas, bootstrapAureliaApp } from './preview/render';
|
|
2
|
+
import Aurelia from 'aurelia';
|
|
3
|
+
|
|
4
|
+
// Track the current story's cleanup function
|
|
5
|
+
let currentCleanup: (() => void) | null = null;
|
|
6
|
+
|
|
7
|
+
export const render = (args: any, context: any) => {
|
|
8
|
+
// Clean up previous story if exists
|
|
9
|
+
if (currentCleanup) {
|
|
10
|
+
currentCleanup();
|
|
11
|
+
currentCleanup = null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Create a container element
|
|
15
|
+
const container = document.createElement('div');
|
|
16
|
+
|
|
17
|
+
// Get the story function result
|
|
18
|
+
const story = context.storyFn();
|
|
19
|
+
|
|
20
|
+
// Bootstrap Aurelia app immediately
|
|
21
|
+
if (story && (story.Component || story.template)) {
|
|
22
|
+
const app = bootstrapAureliaApp(
|
|
23
|
+
story,
|
|
24
|
+
args,
|
|
25
|
+
container,
|
|
26
|
+
story.Component || context.component
|
|
27
|
+
) as Aurelia;
|
|
28
|
+
|
|
29
|
+
// Start the app asynchronously
|
|
30
|
+
const startPromise = app.start();
|
|
31
|
+
if (startPromise && typeof startPromise.catch === 'function') {
|
|
32
|
+
startPromise.catch((error: any) => {
|
|
33
|
+
console.error('Failed to start Aurelia app:', error);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Set cleanup function
|
|
38
|
+
currentCleanup = () => {
|
|
39
|
+
const stopPromise = app.stop();
|
|
40
|
+
if (stopPromise && typeof stopPromise.catch === 'function') {
|
|
41
|
+
stopPromise.catch((error: any) => {
|
|
42
|
+
console.error('Failed to stop Aurelia app:', error);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Return the container element immediately
|
|
49
|
+
return container;
|
|
50
|
+
};
|
package/src/webpack.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/webpack.ts
|
|
2
|
+
import type { RuleSetRule } from 'webpack';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A set of rules to be added to the webpack configuration.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function getRules(): RuleSetRule[] {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
test: /\.ts$/i,
|
|
12
|
+
use: ['ts-loader', '@aurelia/webpack-loader'],
|
|
13
|
+
exclude: /node_modules/,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
test: /\.html$/i,
|
|
17
|
+
use: '@aurelia/webpack-loader',
|
|
18
|
+
exclude: /node_modules/,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { STORY_CHANGED } from '@storybook/core-events';
|
|
2
|
-
import { render, renderToCanvas, bootstrapAureliaApp, createComponentTemplate, } from '../src/preview/render';
|
|
3
|
-
// Add this at the very top of the file, before any imports.
|
|
4
|
-
jest.mock('aurelia', () => {
|
|
5
|
-
const actual = jest.requireActual('aurelia');
|
|
6
|
-
return {
|
|
7
|
-
...actual,
|
|
8
|
-
CustomElement: {
|
|
9
|
-
...actual.CustomElement,
|
|
10
|
-
getDefinition: jest.fn().mockReturnValue({
|
|
11
|
-
name: 'dummy-comp',
|
|
12
|
-
bindables: { prop: { attribute: 'prop', name: 'prop' } },
|
|
13
|
-
}),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
describe('render', () => {
|
|
18
|
-
it('throws an error when no component is provided', () => {
|
|
19
|
-
expect(() => render({}, { id: 'story-1', component: undefined })).toThrowError('Unable to render story story-1 as the component annotation is missing from the default export');
|
|
20
|
-
});
|
|
21
|
-
it('returns the expected object when a component is provided', () => {
|
|
22
|
-
const DummyComponent = () => { };
|
|
23
|
-
const args = { foo: 'bar' };
|
|
24
|
-
const result = render(args, { id: 'story-1', component: DummyComponent });
|
|
25
|
-
expect(result).toEqual({ Component: DummyComponent, props: args, template: '' });
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('renderToCanvas', () => {
|
|
29
|
-
let canvas;
|
|
30
|
-
let dummyChannel;
|
|
31
|
-
const DummyComponent = class {
|
|
32
|
-
};
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
canvas = document.createElement('div');
|
|
35
|
-
dummyChannel = { on: jest.fn(), off: jest.fn() };
|
|
36
|
-
});
|
|
37
|
-
it('calls showError when the story function returns a falsy value', async () => {
|
|
38
|
-
const storyFn = jest.fn(() => null);
|
|
39
|
-
const showError = jest.fn();
|
|
40
|
-
const showMain = jest.fn();
|
|
41
|
-
const context = {
|
|
42
|
-
storyFn,
|
|
43
|
-
title: 'Test Title',
|
|
44
|
-
name: 'Test Story',
|
|
45
|
-
showMain,
|
|
46
|
-
showError,
|
|
47
|
-
storyContext: {
|
|
48
|
-
parameters: {},
|
|
49
|
-
component: DummyComponent,
|
|
50
|
-
args: {},
|
|
51
|
-
viewMode: 'story',
|
|
52
|
-
channel: dummyChannel,
|
|
53
|
-
},
|
|
54
|
-
forceRemount: false,
|
|
55
|
-
};
|
|
56
|
-
const cleanup = await renderToCanvas(context, canvas);
|
|
57
|
-
expect(showError).toHaveBeenCalled();
|
|
58
|
-
expect(typeof cleanup).toBe('function');
|
|
59
|
-
});
|
|
60
|
-
it('bootstraps an Aurelia app when none exists or forceRemount is true', async () => {
|
|
61
|
-
const fakeAurelia = {
|
|
62
|
-
start: jest.fn().mockResolvedValue(undefined),
|
|
63
|
-
stop: jest.fn().mockResolvedValue(undefined),
|
|
64
|
-
root: { controller: { viewModel: {} } },
|
|
65
|
-
};
|
|
66
|
-
const story = { template: '<div></div>', props: { test: 'value' } };
|
|
67
|
-
const storyFn = jest.fn(() => story);
|
|
68
|
-
const showError = jest.fn();
|
|
69
|
-
const showMain = jest.fn();
|
|
70
|
-
// Spy on bootstrapAureliaApp to simulate app creation.
|
|
71
|
-
const bootstrapSpy = jest
|
|
72
|
-
.spyOn(require('../src/preview/render'), 'bootstrapAureliaApp')
|
|
73
|
-
.mockReturnValue(fakeAurelia);
|
|
74
|
-
const context = {
|
|
75
|
-
storyFn,
|
|
76
|
-
title: 'Test Title',
|
|
77
|
-
name: 'Test Story',
|
|
78
|
-
showMain,
|
|
79
|
-
showError,
|
|
80
|
-
storyContext: {
|
|
81
|
-
parameters: { args: { param: 'foo' } },
|
|
82
|
-
component: DummyComponent,
|
|
83
|
-
args: { test: 'bar' },
|
|
84
|
-
viewMode: 'story',
|
|
85
|
-
channel: dummyChannel,
|
|
86
|
-
},
|
|
87
|
-
forceRemount: false,
|
|
88
|
-
};
|
|
89
|
-
const cleanup = await renderToCanvas(context, canvas, bootstrapAureliaApp);
|
|
90
|
-
expect(showError).not.toHaveBeenCalled();
|
|
91
|
-
expect(showMain).toHaveBeenCalled();
|
|
92
|
-
expect(bootstrapSpy).toHaveBeenCalled();
|
|
93
|
-
// Simulate cleanup (which should remove the STORY_CHANGED listener)
|
|
94
|
-
await cleanup();
|
|
95
|
-
expect(dummyChannel.off).toHaveBeenCalledWith(STORY_CHANGED, expect.any(Function));
|
|
96
|
-
bootstrapSpy.mockRestore();
|
|
97
|
-
});
|
|
98
|
-
it('updates the existing app viewModel when re-rendering without forceRemount', async () => {
|
|
99
|
-
// Create a fake Aurelia app with a mutable viewModel.
|
|
100
|
-
const fakeViewModel = {};
|
|
101
|
-
const fakeAurelia = {
|
|
102
|
-
start: jest.fn().mockResolvedValue(undefined),
|
|
103
|
-
stop: jest.fn().mockResolvedValue(undefined),
|
|
104
|
-
root: { controller: { viewModel: fakeViewModel } },
|
|
105
|
-
};
|
|
106
|
-
const story = { template: '<div></div>', props: { test: 'initial' } };
|
|
107
|
-
const storyFn = jest.fn(() => story);
|
|
108
|
-
const showError = jest.fn();
|
|
109
|
-
const showMain = jest.fn();
|
|
110
|
-
const bootstrapSpy = jest
|
|
111
|
-
.spyOn(require('../src/preview/render'), 'bootstrapAureliaApp')
|
|
112
|
-
.mockReturnValue(fakeAurelia);
|
|
113
|
-
// First render: bootstrap the app.
|
|
114
|
-
const context = {
|
|
115
|
-
storyFn,
|
|
116
|
-
title: 'Title',
|
|
117
|
-
name: 'Name',
|
|
118
|
-
showMain,
|
|
119
|
-
showError,
|
|
120
|
-
storyContext: {
|
|
121
|
-
parameters: { args: { param: 'foo' } },
|
|
122
|
-
component: DummyComponent,
|
|
123
|
-
args: { test: 'bar' },
|
|
124
|
-
viewMode: 'story',
|
|
125
|
-
channel: dummyChannel,
|
|
126
|
-
},
|
|
127
|
-
forceRemount: false,
|
|
128
|
-
};
|
|
129
|
-
await renderToCanvas(context, canvas, bootstrapAureliaApp);
|
|
130
|
-
expect(bootstrapSpy).toHaveBeenCalledTimes(1);
|
|
131
|
-
// Second render with new args; should update viewModel instead of re-bootstrap.
|
|
132
|
-
const newStory = { template: '<div></div>', props: { test: 'updated' } };
|
|
133
|
-
storyFn.mockReturnValueOnce(newStory);
|
|
134
|
-
const newContext = {
|
|
135
|
-
...context,
|
|
136
|
-
storyContext: {
|
|
137
|
-
...context.storyContext,
|
|
138
|
-
parameters: { args: { param: 'baz' } },
|
|
139
|
-
args: { test: 'qux' },
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
await renderToCanvas(newContext, canvas, bootstrapAureliaApp);
|
|
143
|
-
expect(bootstrapSpy).toHaveBeenCalledTimes(1);
|
|
144
|
-
expect(fakeViewModel).toEqual({ param: 'baz', test: 'qux' });
|
|
145
|
-
bootstrapSpy.mockRestore();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('createComponentTemplate', () => {
|
|
149
|
-
it('generates the correct template string', () => {
|
|
150
|
-
const DummyComponent = class {
|
|
151
|
-
};
|
|
152
|
-
// The definition is already provided via module mocking.
|
|
153
|
-
const template = createComponentTemplate(DummyComponent, '<span>inner</span>');
|
|
154
|
-
expect(template).toBe('<dummy-comp prop.bind="prop"><span>inner</span></dummy-comp>');
|
|
155
|
-
});
|
|
156
|
-
});
|
package/dist/index.d.ts
DELETED
package/dist/preset.d.ts
DELETED
package/dist/preview/render.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RenderContext, ArgsStoryFn } from '@storybook/types';
|
|
2
|
-
import type { AureliaRenderer } from './types';
|
|
3
|
-
import Aurelia, { Constructable } from 'aurelia';
|
|
4
|
-
interface AureliaStoryResult {
|
|
5
|
-
template: string;
|
|
6
|
-
components?: unknown[];
|
|
7
|
-
Component?: unknown;
|
|
8
|
-
container?: any;
|
|
9
|
-
items?: unknown[];
|
|
10
|
-
innerHtml?: string;
|
|
11
|
-
props?: Record<string, any>;
|
|
12
|
-
}
|
|
13
|
-
export declare const render: ArgsStoryFn<AureliaRenderer>;
|
|
14
|
-
export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement): Promise<() => void>;
|
|
15
|
-
export declare function bootstrapAureliaApp(story: AureliaStoryResult, args: Record<string, any>, domElement: HTMLElement, component?: Constructable): Omit<Aurelia, "enhance" | "register" | "app">;
|
|
16
|
-
export declare function createComponentTemplate(component: Constructable, innerHtml?: string): string;
|
|
17
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { render, renderToCanvas, createComponentTemplate } from './render';
|
|
2
|
-
import { STORY_CHANGED } from '@storybook/core-events';
|
|
3
|
-
import { CustomElement } from 'aurelia';
|
|
4
|
-
// Dummy component for testing
|
|
5
|
-
class DummyComponent {
|
|
6
|
-
}
|
|
7
|
-
// ----------------------
|
|
8
|
-
// Tests for render()
|
|
9
|
-
// ----------------------
|
|
10
|
-
describe('render()', () => {
|
|
11
|
-
test('should return object with component, props, and empty template', () => {
|
|
12
|
-
const args = { foo: 'bar' };
|
|
13
|
-
const context = { id: 'story-1', component: DummyComponent };
|
|
14
|
-
const result = render(args, context);
|
|
15
|
-
expect(result).toEqual({ Component: DummyComponent, props: args, template: '' });
|
|
16
|
-
});
|
|
17
|
-
test('should throw error if component is missing', () => {
|
|
18
|
-
const args = {};
|
|
19
|
-
const context = { id: 'story-2', component: undefined };
|
|
20
|
-
expect(() => render(args, context)).toThrowError(/Unable to render story/);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
// ----------------------
|
|
24
|
-
// Tests for createComponentTemplate()
|
|
25
|
-
// ----------------------
|
|
26
|
-
describe('createComponentTemplate()', () => {
|
|
27
|
-
test('should return a proper template string', () => {
|
|
28
|
-
// Create a fake definition for the dummy component
|
|
29
|
-
const fakeDefinition = {
|
|
30
|
-
name: 'dummy-comp',
|
|
31
|
-
bindables: {
|
|
32
|
-
prop1: { attribute: 'data-prop', name: 'prop1' },
|
|
33
|
-
prop2: { attribute: 'data-attr', name: 'prop2' }
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// Spy on CustomElement.getDefinition to return our fake definition
|
|
37
|
-
const getDefinitionSpy = jest
|
|
38
|
-
.spyOn(CustomElement, 'getDefinition')
|
|
39
|
-
.mockReturnValue(fakeDefinition);
|
|
40
|
-
const template = createComponentTemplate(DummyComponent, 'inner content');
|
|
41
|
-
expect(template).toBe('<dummy-comp data-prop.bind="prop1" data-attr.bind="prop2">inner content</dummy-comp>');
|
|
42
|
-
// Restore the original function
|
|
43
|
-
getDefinitionSpy.mockRestore();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
// ----------------------
|
|
47
|
-
// Tests for renderToCanvas()
|
|
48
|
-
// ----------------------
|
|
49
|
-
describe('renderToCanvas()', () => {
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
// If needed, clear/reset any globals here.
|
|
52
|
-
});
|
|
53
|
-
test('should call showError if the story is undefined', async () => {
|
|
54
|
-
const canvasElement = document.createElement('div');
|
|
55
|
-
const showError = jest.fn();
|
|
56
|
-
const showMain = jest.fn();
|
|
57
|
-
// storyFn returns undefined to simulate missing Aurelia story result
|
|
58
|
-
const storyFn = jest.fn(() => undefined);
|
|
59
|
-
const storyContext = {
|
|
60
|
-
parameters: { args: { a: 1 } },
|
|
61
|
-
args: { b: 2 },
|
|
62
|
-
component: DummyComponent,
|
|
63
|
-
viewMode: 'story',
|
|
64
|
-
channel: { on: jest.fn(), off: jest.fn() }
|
|
65
|
-
};
|
|
66
|
-
const context = {
|
|
67
|
-
storyFn,
|
|
68
|
-
title: 'Test Title',
|
|
69
|
-
name: 'Test Story',
|
|
70
|
-
showMain,
|
|
71
|
-
showError,
|
|
72
|
-
forceRemount: false,
|
|
73
|
-
storyContext
|
|
74
|
-
};
|
|
75
|
-
// Calling renderToCanvas should immediately call showError.
|
|
76
|
-
const teardownFn = await renderToCanvas(context, canvasElement);
|
|
77
|
-
expect(showError).toHaveBeenCalled();
|
|
78
|
-
// Teardown function exists even if error occurred.
|
|
79
|
-
await teardownFn();
|
|
80
|
-
});
|
|
81
|
-
test('should bootstrap Aurelia app and execute teardown properly', async () => {
|
|
82
|
-
const canvasElement = document.createElement('div');
|
|
83
|
-
const showError = jest.fn();
|
|
84
|
-
const showMain = jest.fn();
|
|
85
|
-
const fakeChannel = { on: jest.fn(), off: jest.fn() };
|
|
86
|
-
// A valid Aurelia story result
|
|
87
|
-
const storyResult = { template: '<div></div>', container: {} };
|
|
88
|
-
const storyFn = jest.fn(() => storyResult);
|
|
89
|
-
const storyContext = {
|
|
90
|
-
parameters: { args: { testProp: true } },
|
|
91
|
-
args: { testProp: false },
|
|
92
|
-
component: DummyComponent,
|
|
93
|
-
viewMode: 'story',
|
|
94
|
-
channel: fakeChannel
|
|
95
|
-
};
|
|
96
|
-
const context = {
|
|
97
|
-
storyFn,
|
|
98
|
-
title: 'Success Title',
|
|
99
|
-
name: 'Success Story',
|
|
100
|
-
showMain,
|
|
101
|
-
showError,
|
|
102
|
-
forceRemount: false,
|
|
103
|
-
storyContext
|
|
104
|
-
};
|
|
105
|
-
// Fake Aurelia instance with start and stop methods
|
|
106
|
-
const fakeAurelia = {
|
|
107
|
-
start: jest.fn().mockResolvedValue(undefined),
|
|
108
|
-
stop: jest.fn().mockResolvedValue(undefined),
|
|
109
|
-
root: { controller: { viewModel: {} } }
|
|
110
|
-
};
|
|
111
|
-
// Stub bootstrapAureliaApp to return our fake Aurelia instance.
|
|
112
|
-
const { bootstrapAureliaApp } = await import('./render');
|
|
113
|
-
const bootstrapSpy = jest
|
|
114
|
-
.spyOn(require('./render'), 'bootstrapAureliaApp')
|
|
115
|
-
.mockResolvedValue(fakeAurelia);
|
|
116
|
-
const teardown = await renderToCanvas(context, canvasElement);
|
|
117
|
-
expect(showMain).toHaveBeenCalled();
|
|
118
|
-
expect(fakeChannel.on).toHaveBeenCalledWith(STORY_CHANGED, expect.any(Function));
|
|
119
|
-
expect(fakeAurelia.start).toHaveBeenCalled();
|
|
120
|
-
// Call the teardown function and verify cleanup calls.
|
|
121
|
-
await teardown();
|
|
122
|
-
expect(fakeChannel.off).toHaveBeenCalledWith(STORY_CHANGED, expect.any(Function));
|
|
123
|
-
expect(fakeAurelia.stop).toHaveBeenCalled();
|
|
124
|
-
jest.restoreAllMocks();
|
|
125
|
-
});
|
|
126
|
-
});
|
package/dist/preview/types.d.ts
DELETED
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
package/dist/src/preset.d.ts
DELETED
package/dist/src/preset.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/preset.ts
|
|
2
|
-
// Minimal preset for Storybook-Aurelia2
|
|
3
|
-
/**
|
|
4
|
-
* Optionally adjust the Vite configuration.
|
|
5
|
-
*/
|
|
6
|
-
export async function viteFinal(config) {
|
|
7
|
-
// For now, return the config unchanged.
|
|
8
|
-
return config;
|
|
9
|
-
}
|
|
10
|
-
// Export a default for compatibility.
|
|
11
|
-
export default { viteFinal };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RenderContext, ArgsStoryFn } from '@storybook/types';
|
|
2
|
-
import type { AureliaRenderer } from './types';
|
|
3
|
-
import Aurelia, { Constructable } from 'aurelia';
|
|
4
|
-
interface AureliaStoryResult {
|
|
5
|
-
template: string;
|
|
6
|
-
components?: unknown[];
|
|
7
|
-
Component?: unknown;
|
|
8
|
-
container?: any;
|
|
9
|
-
items?: unknown[];
|
|
10
|
-
innerHtml?: string;
|
|
11
|
-
props?: Record<string, any>;
|
|
12
|
-
}
|
|
13
|
-
export declare const render: ArgsStoryFn<AureliaRenderer>;
|
|
14
|
-
export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement, bootstrapAppFn?: typeof bootstrapAureliaApp): Promise<() => void>;
|
|
15
|
-
export declare function bootstrapAureliaApp(story: AureliaStoryResult, args: Record<string, any>, domElement: HTMLElement, component?: Constructable): Omit<Aurelia, "enhance" | "register" | "app">;
|
|
16
|
-
export declare function createComponentTemplate(component: Constructable, innerHtml?: string): string;
|
|
17
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|