Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions packages/app/src/cli/services/build/client-steps.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import {ExtensionBuildOptions} from './extension.js'
import {executeStep, BuildContext} from './client-steps.js'
import {ExtensionInstance} from '../../models/extensions/extension-instance.js'
import {describe, expect, test} from 'vitest'
import {inTemporaryDirectory, writeFile, readFile, mkdir, fileExists} from '@shopify/cli-kit/node/fs'
import {joinPath} from '@shopify/cli-kit/node/path'
import {Writable} from 'stream'

function buildOptions(): ExtensionBuildOptions {
return {
stdout: new Writable({
write(_chunk, _encoding, callback) {
callback()
},
}),
stderr: new Writable({
write(_chunk, _encoding, callback) {
callback()
},
}),
app: {} as any,
environment: 'production',
}
}

describe('client_steps integration', () => {
test('executes include_assets step and copies files to output', async () => {
await inTemporaryDirectory(async (tmpDir) => {
// Setup: Create extension directory with assets
const extensionDir = joinPath(tmpDir, 'extension')
const assetsDir = joinPath(extensionDir, 'assets')
const outputDir = joinPath(tmpDir, 'output')

await mkdir(extensionDir)
await mkdir(assetsDir)
await mkdir(outputDir)

// Create test files
await writeFile(joinPath(assetsDir, 'logo.png'), 'fake-png-data')
await writeFile(joinPath(assetsDir, 'style.css'), 'body { color: red; }')

const mockExtension = {
directory: extensionDir,
outputPath: joinPath(outputDir, 'extension.js'),
} as ExtensionInstance

const context: BuildContext = {extension: mockExtension, options: buildOptions(), stepResults: new Map()}

await executeStep(
{
id: 'copy-assets',
name: 'Copy Assets',
type: 'include_assets',
config: {
inclusions: [{type: 'pattern', baseDir: 'assets', include: ['**/*']}],
},
},
context,
)

// Verify: Files were copied to output directory
const logoExists = await fileExists(joinPath(outputDir, 'logo.png'))
const styleExists = await fileExists(joinPath(outputDir, 'style.css'))

expect(logoExists).toBe(true)
expect(styleExists).toBe(true)

const logoContent = await readFile(joinPath(outputDir, 'logo.png'))
const styleContent = await readFile(joinPath(outputDir, 'style.css'))

expect(logoContent).toBe('fake-png-data')
expect(styleContent).toBe('body { color: red; }')
})
})

test('executes multiple steps in sequence', async () => {
await inTemporaryDirectory(async (tmpDir) => {
// Setup: Create extension with two asset directories
const extensionDir = joinPath(tmpDir, 'extension')
const imagesDir = joinPath(extensionDir, 'images')
const stylesDir = joinPath(extensionDir, 'styles')
const outputDir = joinPath(tmpDir, 'output')

await mkdir(extensionDir)
await mkdir(imagesDir)
await mkdir(stylesDir)
await mkdir(outputDir)

await writeFile(joinPath(imagesDir, 'logo.png'), 'logo-data')
await writeFile(joinPath(stylesDir, 'main.css'), 'css-data')

const mockExtension = {
directory: extensionDir,
outputPath: joinPath(outputDir, 'extension.js'),
} as ExtensionInstance

const context: BuildContext = {extension: mockExtension, options: buildOptions(), stepResults: new Map()}

await executeStep(
{
id: 'copy-images',
name: 'Copy Images',
type: 'include_assets',
config: {
inclusions: [{type: 'pattern', baseDir: 'images', include: ['**/*'], destination: 'assets/images'}],
},
},
context,
)
await executeStep(
{
id: 'copy-styles',
name: 'Copy Styles',
type: 'include_assets',
config: {
inclusions: [{type: 'pattern', baseDir: 'styles', include: ['**/*'], destination: 'assets/styles'}],
},
},
context,
)

// Verify: Files from both steps were copied to correct destinations
const logoExists = await fileExists(joinPath(outputDir, 'assets/images/logo.png'))
const styleExists = await fileExists(joinPath(outputDir, 'assets/styles/main.css'))

expect(logoExists).toBe(true)
expect(styleExists).toBe(true)
})
})

test('silently skips configKey step when config key is absent from extension config', async () => {
await inTemporaryDirectory(async (tmpDir) => {
const extensionDir = joinPath(tmpDir, 'extension')
const outputDir = joinPath(tmpDir, 'output')

await mkdir(extensionDir)
await mkdir(outputDir)

// Extension has no configuration — static_root key is absent
const mockExtension = {
directory: extensionDir,
outputPath: joinPath(outputDir, 'extension.js'),
configuration: {},
} as unknown as ExtensionInstance

const context: BuildContext = {extension: mockExtension, options: buildOptions(), stepResults: new Map()}

// Should not throw — absent configKey values are silently skipped
await expect(
executeStep(
{
id: 'copy-static-assets',
name: 'Copy Static Assets',
type: 'include_assets',
config: {inclusions: [{type: 'configKey', key: 'static_root'}]},
},
context,
),
).resolves.not.toThrow()
})
})
})
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/build/client-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface LifecycleStep {
| 'validate'
| 'transform'
| 'custom'
| 'build_manifest'

/** Step-specific configuration */
readonly config: {[key: string]: unknown}
Expand Down Expand Up @@ -60,7 +61,7 @@ export interface BuildContext {
[key: string]: unknown
}

type StepResult = {
export type StepResult = {
readonly id: string
readonly duration: number
} & (
Expand Down
Loading
Loading