Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacroldan committed Nov 21, 2024
1 parent 053c331 commit 838279a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe('app-event-watcher build extension errors', () => {
}

const mockManager = new MockESBuildContextManager()
mockManager.contexts.h1.rebuild.mockRejectedValueOnce(esbuildError)
mockManager.rebuildContext = vi.fn().mockRejectedValueOnce(esbuildError)

const buildOutputPath = joinPath(tmpDir, '.shopify', 'bundle')
const app = testAppLinked({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {DevAppWatcherOptions, ESBuildContextManager} from './app-watcher-esbuild
import {AppEvent, EventType} from './app-event-watcher.js'
import {testAppLinked, testUIExtension} from '../../../models/app/app.test-data.js'
import {describe, expect, test, vi} from 'vitest'
import * as fs from '@shopify/cli-kit/node/fs'

vi.mock('@luckycatfactory/esbuild-graphql-loader', () => ({
default: {
Expand All @@ -15,13 +16,14 @@ const extension1 = await testUIExtension({type: 'ui_extension', handle: 'h1', di
const extension2 = await testUIExtension({type: 'ui_extension', directory: '/extensions/ui_extension_2'})

describe('app-watcher-esbuild', () => {
const options: DevAppWatcherOptions = {
dotEnvVariables: {key: 'value'},
url: 'http://localhost:3000',
outputPath: '/path/to/output',
}

test('creating contexts', async () => {
// Given
const options: DevAppWatcherOptions = {
dotEnvVariables: {key: 'value'},
url: 'http://localhost:3000',
outputPath: '/path/to/output',
}
const manager = new ESBuildContextManager(options)
const extensions = [extension1, extension2]

Expand All @@ -35,11 +37,6 @@ describe('app-watcher-esbuild', () => {

test('deleting contexts', async () => {
// Given
const options: DevAppWatcherOptions = {
dotEnvVariables: {key: 'value'},
url: 'http://localhost:3000',
outputPath: '/path/to/output',
}
const manager = new ESBuildContextManager(options)
const extensions = [extension1, extension2]
await manager.createContexts(extensions)
Expand All @@ -54,11 +51,6 @@ describe('app-watcher-esbuild', () => {

test('updating contexts with an app event', async () => {
// Given
const options: DevAppWatcherOptions = {
dotEnvVariables: {key: 'value'},
url: 'http://localhost:3000',
outputPath: '/path/to/output',
}
const manager = new ESBuildContextManager(options)
await manager.createContexts([extension2])

Expand All @@ -79,4 +71,19 @@ describe('app-watcher-esbuild', () => {
expect(manager.contexts).toHaveProperty('h1')
expect(manager.contexts).not.toHaveProperty('test-ui-extension')
})

test('rebuilding contexts', async () => {
// Given
const manager = new ESBuildContextManager(options)
await manager.createContexts([extension1])
const spyContext = vi.spyOn(manager.contexts.h1!, 'rebuild').mockResolvedValue({} as any)
const spyCopy = vi.spyOn(fs, 'copyFile').mockResolvedValue()

// When
await manager.rebuildContext(extension1)

// Then
expect(spyContext).toHaveBeenCalled()
expect(spyCopy).toHaveBeenCalledWith('/path/to/output/h1/dist', '/extensions/ui_extension_1/dist')
})
})

0 comments on commit 838279a

Please sign in to comment.