1- import { runCommand } from '@oclif/test'
2- import { expect } from 'chai'
1+ import { runCommand } from '@oclif/test'
2+ import { expect } from 'chai'
33import chokidar , { FSWatcher } from 'chokidar'
44import * as fs from 'node:fs'
55import * as path from 'node:path'
6- import { fileURLToPath } from 'node:url'
6+ import { fileURLToPath } from 'node:url'
77import sinon from 'sinon'
88
9+ import Dev from '../../../../src/commands/theme/component/dev.js'
910import Install from '../../../../src/commands/theme/component/install.js'
10- import GenerateImportMap from '../../../../src/commands/theme/generate/import-map.js'
1111import GenerateTemplateMap from '../../../../src/commands/theme/generate/template-map.js'
1212
1313const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
@@ -22,34 +22,33 @@ describe('theme component dev', () => {
2222
2323 beforeEach ( ( ) => {
2424 sandbox = sinon . createSandbox ( )
25- fs . cpSync ( collectionPath , testCollectionPath , { recursive : true } )
26- fs . cpSync ( themePath , testThemePath , { recursive : true } )
25+ fs . cpSync ( collectionPath , testCollectionPath , { recursive : true } )
26+ fs . cpSync ( themePath , testThemePath , { recursive : true } )
2727 process . chdir ( testCollectionPath )
2828 } )
2929
3030 afterEach ( ( ) => {
3131 sandbox . restore ( )
32- fs . rmSync ( testCollectionPath , { force : true , recursive : true } )
33- fs . rmSync ( testThemePath , { force : true , recursive : true } )
32+ fs . rmSync ( testCollectionPath , { force : true , recursive : true } )
33+ fs . rmSync ( testThemePath , { force : true , recursive : true } )
3434 } )
3535
3636 it ( 'copies the component setup files to the dev directory' , async ( ) => {
37- await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , '../test-theme' ] )
37+ await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , testThemePath ] )
3838 expect ( fs . existsSync ( path . join ( testCollectionPath , '.dev' , 'sections' , 'with-setup.liquid' ) ) ) . to . be . true
3939 expect ( fs . existsSync ( path . join ( testCollectionPath , '.dev' , 'templates' , 'index.with-setup.liquid' ) ) ) . to . be . true
4040 } )
4141
4242 it ( 'merges the settings_schema.json setup files' , async ( ) => {
43- await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , '../test-theme' ] )
43+ await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , testThemePath ] )
4444 expect ( fs . existsSync ( path . join ( testCollectionPath , '.dev' , 'config' , 'settings_schema.json' ) ) ) . to . be . true
4545 const json = fs . readFileSync ( path . join ( testCollectionPath , '.dev' , 'config' , 'settings_schema.json' ) , 'utf8' )
4646 const jsonObject = JSON . parse ( json )
4747 expect ( jsonObject ) . to . have . deep . members ( [ { name : "schema_1" } , { name : "schema_2" } , { name : "schema_3" } ] )
48-
4948 } )
5049
5150 it ( 'merges the settings_data.json setup files' , async ( ) => {
52- await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , '../test-theme' ] )
51+ await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , testThemePath ] )
5352 expect ( fs . existsSync ( path . join ( testCollectionPath , '.dev' , 'config' , 'settings_data.json' ) ) ) . to . be . true
5453 const json = fs . readFileSync ( path . join ( testCollectionPath , '.dev' , 'config' , 'settings_data.json' ) , 'utf8' )
5554 const jsonObject = JSON . parse ( json )
@@ -58,7 +57,7 @@ describe('theme component dev', () => {
5857 } )
5958
6059 it ( 'copies a selected component setup file to the dev directory' , async ( ) => {
61- await runCommand ( [ 'theme' , 'component' , 'dev' , 'with-setup' , '-t' , '../test-theme' , ] )
60+ await runCommand ( [ 'theme' , 'component' , 'dev' , 'with-setup' , '-t' , testThemePath ] )
6261 expect ( fs . existsSync ( path . join ( testCollectionPath , '.dev' , 'sections' , 'with-setup.liquid' ) ) ) . to . be . true
6362 expect ( fs . existsSync ( path . join ( testCollectionPath , '.dev' , 'templates' , 'index.with-setup.liquid' ) ) ) . to . be . true
6463
@@ -67,50 +66,50 @@ describe('theme component dev', () => {
6766 } )
6867
6968 it ( 'runs the install command' , async ( ) => {
70- const installRunSpy = sandbox . spy ( Install . prototype , 'run' )
69+ const installRunStub = sandbox . stub ( Install , 'run' ) . resolves ( )
70+ sandbox . stub ( Dev . prototype , 'log' ) . returns ( )
7171
72- await runCommand ( [ 'theme ' , 'component' , 'dev' , '-t ', '../test-theme ' ] )
72+ await Dev . run ( [ '-t ' , testThemePath , '--no-preview ' , '--no-watch ' ] )
7373
74- expect ( installRunSpy . calledOnce ) . to . be . true
74+ expect ( installRunStub . called ) . to . be . true
7575 } )
7676
7777 it ( 'runs the generate import map command' , async ( ) => {
78- const generateImportMapRunSpy = sandbox . spy ( GenerateImportMap . prototype , 'run' )
78+ const installRunStub = sandbox . stub ( Install , 'run' ) . resolves ( )
79+ sandbox . stub ( Dev . prototype , 'log' ) . returns ( )
80+
81+ await Dev . run ( [ '-t' , testThemePath , '--no-preview' , '--no-watch' ] )
7982
80- await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , '../test-theme' , '--no-preview' , '--no-watch' ] )
81-
82- expect ( generateImportMapRunSpy . callCount ) . to . be . greaterThan ( 0 )
83- expect ( generateImportMapRunSpy . called ) . to . be . true
83+ expect ( installRunStub . called ) . to . be . true
8484 } )
8585
8686 it ( 'runs the generate template map command' , async ( ) => {
87- const generateTemplateMapRunSpy = sandbox . spy ( GenerateTemplateMap . prototype , 'run' )
87+ const generateTemplateMapRunStub = sandbox . stub ( GenerateTemplateMap , 'run' ) . resolves ( )
88+ sandbox . stub ( Dev . prototype , 'log' ) . returns ( )
89+ sandbox . stub ( Install , 'run' ) . resolves ( )
8890
89- await runCommand ( [ 'theme ' , 'component' , 'dev' , '-t' , '../test-theme ', '--no-preview ' , '--no-watch ' ] )
91+ await Dev . run ( [ '-t ' , testThemePath , '--no-preview ' , '--no-watch ' , '--generate-template-map ' ] )
9092
91- expect ( generateTemplateMapRunSpy . calledOnce ) . to . be . true
93+ expect ( generateTemplateMapRunStub . called ) . to . be . true
9294 } )
9395
9496 it ( 'watches for changes to the theme and components and rebuilds the theme' , async ( ) => {
9597 const watchStub = sandbox . stub ( chokidar , 'watch' )
96- // Mock the watch method to return a minimal watcher interface
9798 const onStub = sandbox . stub ( )
9899 const mockWatcher : Partial < FSWatcher > = {
99100 emit : sandbox . stub ( ) ,
100101 on : onStub
101102 }
102103 watchStub . returns ( mockWatcher as FSWatcher )
103104
104- // Set NODE_ENV to test
105105 const originalEnv = process . env . NODE_ENV
106106 process . env . NODE_ENV = 'test'
107107
108- await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , '../test-theme' , '--watch' , '--no-preview' ] )
108+ await runCommand ( [ 'theme' , 'component' , 'dev' , '-t' , testThemePath , '--watch' , '--no-preview' ] )
109109
110110 expect ( watchStub . calledOnce ) . to . be . true
111111 expect ( watchStub . firstCall . args [ 0 ] ) . to . deep . equal ( [ path . join ( testThemePath ) , path . join ( testCollectionPath , 'components' ) ] )
112-
113- // Restore NODE_ENV
112+
114113 process . env . NODE_ENV = originalEnv
115114 } )
116115} )
0 commit comments