1
+ const test = require ( 'ava' ) ;
2
+ const fs = require ( 'fs' ) ;
3
+ const path = require ( 'path' ) ;
4
+
5
+ test ( 'Storybook configuration files exist' , t => {
6
+ // Check main config
7
+ const mainPath = path . join ( __dirname , '..' , 'common' , 'storybook-main.ext__if_storybook' ) ;
8
+ t . true ( fs . existsSync ( mainPath ) , 'Storybook main config should exist' ) ;
9
+
10
+ // Check preview config
11
+ const previewPath = path . join ( __dirname , '..' , 'common' , 'storybook-preview.ext__if_storybook' ) ;
12
+ t . true ( fs . existsSync ( previewPath ) , 'Storybook preview config should exist' ) ;
13
+
14
+ // Check README
15
+ const readmePath = path . join ( __dirname , '..' , 'storybook__if_storybook' , 'README.md' ) ;
16
+ t . true ( fs . existsSync ( readmePath ) , 'Storybook README should exist' ) ;
17
+ } ) ;
18
+
19
+ test ( 'Storybook configuration includes both Vite and Webpack setups' , t => {
20
+ const mainPath = path . join ( __dirname , '..' , 'common' , 'storybook-main.ext__if_storybook' ) ;
21
+ const content = fs . readFileSync ( mainPath , 'utf8' ) ;
22
+
23
+ t . true ( content . includes ( '@aurelia/storybook' ) , 'Should use Aurelia Storybook framework' ) ;
24
+ t . true ( content . includes ( '@storybook/builder-vite' ) , 'Should use Vite builder' ) ;
25
+ t . true ( content . includes ( '@storybook/builder-webpack5' ) , 'Should use Webpack5 builder' ) ;
26
+ t . true ( content . includes ( '@storybook/addon-links' ) , 'Should include links addon' ) ;
27
+ t . true ( content . includes ( 'viteFinal' ) , 'Should have viteFinal configuration' ) ;
28
+ t . true ( content . includes ( '@aurelia/runtime-html' ) , 'Should exclude Aurelia runtime from optimization' ) ;
29
+ t . true ( content . includes ( '/* @if vite */' ) , 'Should have Vite conditional' ) ;
30
+ t . true ( content . includes ( '/* @if webpack */' ) , 'Should have Webpack conditional' ) ;
31
+ } ) ;
32
+
33
+ test ( 'Storybook Webpack configuration is included' , t => {
34
+ const mainPath = path . join ( __dirname , '..' , 'common' , 'storybook-main.ext__if_storybook' ) ;
35
+ const content = fs . readFileSync ( mainPath , 'utf8' ) ;
36
+
37
+ t . true ( content . includes ( 'docs: {}' ) , 'Should have docs configuration' ) ;
38
+ } ) ;
39
+
40
+ test ( 'Storybook preview configuration is correct' , t => {
41
+ const previewPath = path . join ( __dirname , '..' , 'common' , 'storybook-preview.ext__if_storybook' ) ;
42
+ const content = fs . readFileSync ( previewPath , 'utf8' ) ;
43
+
44
+ t . true ( content . includes ( "export { render, renderToCanvas } from '@aurelia/storybook'" ) ,
45
+ 'Should export render functions from Aurelia Storybook plugin' ) ;
46
+ } ) ;
47
+
48
+ test ( 'Storybook story files exist and are properly structured' , t => {
49
+ // Check app-min story file
50
+ const appMinStoryPath = path . join ( __dirname , '..' , 'app-min' , 'src' , 'my-app.stories.ext__if_storybook' ) ;
51
+ t . true ( fs . existsSync ( appMinStoryPath ) , 'App-min story file should exist' ) ;
52
+
53
+ const appMinContent = fs . readFileSync ( appMinStoryPath , 'utf8' ) ;
54
+ t . true ( appMinContent . includes ( '/* @if vite */' ) , 'Should have Vite conditional' ) ;
55
+ t . true ( appMinContent . includes ( '/* @if webpack */' ) , 'Should have Webpack conditional' ) ;
56
+ t . true ( appMinContent . includes ( 'import { MyApp }' ) , 'Should import MyApp component' ) ;
57
+
58
+ // Check app-with-router story file
59
+ const routerStoryPath = path . join ( __dirname , '..' , 'app-with-router' , 'src' , 'welcome-page.stories.ext__if_storybook' ) ;
60
+ t . true ( fs . existsSync ( routerStoryPath ) , 'Router app story file should exist' ) ;
61
+
62
+ // Check plugin story file
63
+ const pluginStoryPath = path . join ( __dirname , '..' , 'plugin-min' , 'src' , 'hello-world.stories.ext__if_storybook' ) ;
64
+ t . true ( fs . existsSync ( pluginStoryPath ) , 'Plugin story file should exist' ) ;
65
+ } ) ;
66
+
67
+ test ( 'Vite package.json includes correct Storybook dependencies' , t => {
68
+ const vitePackagePath = path . join ( __dirname , '..' , 'vite' , 'package.json' ) ;
69
+ const content = fs . readFileSync ( vitePackagePath , 'utf8' ) ;
70
+
71
+ t . true ( content . includes ( '"@aurelia/storybook": "^1.0.2"' ) , 'Should include Aurelia Storybook plugin v1.0.2' ) ;
72
+ t . true ( content . includes ( '"storybook": "^9.0.0"' ) , 'Should include Storybook 9' ) ;
73
+ t . true ( content . includes ( '"@storybook/builder-vite": "^9.0.0"' ) , 'Should include Vite builder' ) ;
74
+ t . true ( content . includes ( '"@storybook/addon-links": "^9.0.0"' ) , 'Should include links addon' ) ;
75
+ t . true ( content . includes ( '"@storybook/addon-actions": "^9.0.0"' ) , 'Should include actions addon' ) ;
76
+ t . true ( content . includes ( '"@storybook/test": "^9.0.0-alpha.2"' ) , 'Should include test utilities' ) ;
77
+
78
+ // Check scripts
79
+ t . true ( content . includes ( '"storybook": "storybook dev -p 6006"' ) , 'Should include storybook dev script' ) ;
80
+ t . true ( content . includes ( '"build-storybook": "storybook build"' ) , 'Should include build script' ) ;
81
+ } ) ;
82
+
83
+ test ( 'Webpack package.json includes correct Storybook dependencies' , t => {
84
+ const webpackPackagePath = path . join ( __dirname , '..' , 'webpack' , 'package.json' ) ;
85
+ const content = fs . readFileSync ( webpackPackagePath , 'utf8' ) ;
86
+
87
+ t . true ( content . includes ( '"@aurelia/storybook": "^1.0.2"' ) , 'Should include Aurelia Storybook plugin v1.0.2' ) ;
88
+ t . true ( content . includes ( '"storybook": "^9.0.0"' ) , 'Should include Storybook 9' ) ;
89
+ t . true ( content . includes ( '"@storybook/builder-webpack5": "^9.0.0"' ) , 'Should include Webpack5 builder' ) ;
90
+ t . true ( content . includes ( '"@storybook/addon-links": "^9.0.0"' ) , 'Should include links addon' ) ;
91
+
92
+ // Check scripts
93
+ t . true ( content . includes ( '"storybook": "storybook dev -p 6006"' ) , 'Should include storybook dev script' ) ;
94
+ t . true ( content . includes ( '"build-storybook": "storybook build"' ) , 'Should include build script' ) ;
95
+ } ) ;
96
+
97
+ test ( 'Storybook README contains helpful information' , t => {
98
+ const readmePath = path . join ( __dirname , '..' , 'storybook__if_storybook' , 'README.md' ) ;
99
+ const content = fs . readFileSync ( readmePath , 'utf8' ) ;
100
+
101
+ t . true ( content . includes ( '# Storybook Integration' ) , 'Should have main heading' ) ;
102
+ t . true ( content . includes ( 'npm run storybook' ) , 'Should include dev command' ) ;
103
+ t . true ( content . includes ( 'npm run build-storybook' ) , 'Should include build command' ) ;
104
+ t . true ( content . includes ( 'http://localhost:6006' ) , 'Should mention default port' ) ;
105
+ t . true ( content . includes ( '.stories.ts' ) , 'Should explain story file naming' ) ;
106
+ t . true ( content . includes ( 'Aurelia Storybook' ) , 'Should reference the plugin' ) ;
107
+ } ) ;
108
+
109
+ test ( 'After task includes Storybook setup logic' , t => {
110
+ const afterPath = path . join ( __dirname , '..' , 'after.js' ) ;
111
+ const content = fs . readFileSync ( afterPath , 'utf8' ) ;
112
+
113
+ t . true ( content . includes ( "if (features.includes('storybook'))" ) , 'Should check for storybook feature' ) ;
114
+ t . true ( content . includes ( "fs.mkdirSync('.storybook')" ) , 'Should create .storybook directory' ) ;
115
+ t . true ( content . includes ( 'storybook-main' ) , 'Should reference storybook-main file' ) ;
116
+ t . true ( content . includes ( 'storybook-preview' ) , 'Should reference storybook-preview file' ) ;
117
+ t . true ( content . includes ( '.storybook/main' ) , 'Should move to .storybook/main' ) ;
118
+ t . true ( content . includes ( '.storybook/preview' ) , 'Should move to .storybook/preview' ) ;
119
+ } ) ;
0 commit comments