-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-builder): support slashes in archive filename
- Loading branch information
1 parent
3a0c317
commit 870d00a
Showing
5 changed files
with
115 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
apps/app-builder/src/__tests__/mockFileSystemAndCreateContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import {describe, expect, it} from 'vitest'; | ||
import {resolveString} from '../utils/resolveString'; | ||
import {type PdkBuilderContext} from '../types/command'; | ||
import {PdkPlatformName} from '../constants'; | ||
import {fsModifyingMethodSpies} from '../__tests__/spies/fs'; | ||
import {mockFileSystemAndCreateContext} from '../__tests__/mockFileSystemAndCreateContext'; | ||
import {mockFileSystem} from '../__tests__/mockFileSystem'; | ||
import {DEFAULT_FILE_SYSTEM} from '../__tests__/constants'; | ||
import zip from './zip'; | ||
|
||
const mockDistDirectoryFileSystem = (context: PdkBuilderContext) => { | ||
const outDir: Record<string, unknown> = {}; | ||
const name = resolveString(context.config.name, context); | ||
|
||
context.config.platforms.forEach((platform) => { | ||
outDir[`${platform}-${name}`] = DEFAULT_FILE_SYSTEM; | ||
}); | ||
|
||
return { | ||
[context.config.outDir]: outDir, | ||
}; | ||
}; | ||
|
||
describe('command: zip', () => { | ||
it('does nothing when dry run is passed', async (ctx) => { | ||
expect.assertions(fsModifyingMethodSpies.length); | ||
|
||
const context = await mockFileSystemAndCreateContext(ctx, undefined, {args: {dryRun: true}}); | ||
await mockFileSystem(ctx, mockDistDirectoryFileSystem(context)); | ||
|
||
await zip(context); | ||
|
||
fsModifyingMethodSpies.forEach((spy) => { | ||
expect(spy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it.for([ | ||
{ | ||
version: '1.0.0', | ||
archiveFilename: '{{platform}}-{{name}}-{{version}}.zip', | ||
expectedFilename: '[PLATFORM]-test-1.0.0.zip', | ||
}, | ||
{ | ||
version: '3.0.0-beta', | ||
archiveFilename: '{{platform}}-{{name}}-{{version}}.zip', | ||
expectedFilename: '[PLATFORM]-test-3.0.0-beta.zip', | ||
}, | ||
{ | ||
version: 'dev-123-fix/fix-some-bug', | ||
archiveFilename: '{{platform}}-{{name}}-{{version}}.zip', | ||
expectedFilename: '[PLATFORM]-test-dev-123-fix-fix-some-bug.zip', | ||
}, | ||
])('zips files', async ({version, archiveFilename, expectedFilename}, ctx) => { | ||
expect.assertions(1); | ||
|
||
const platforms = [PdkPlatformName.MyParcelBe, PdkPlatformName.MyParcelNl]; | ||
|
||
const context = await mockFileSystemAndCreateContext(ctx, undefined, { | ||
args: {dryRun: false, version}, | ||
config: { | ||
archiveFilename, | ||
platforms, | ||
}, | ||
}); | ||
|
||
await mockFileSystem(ctx, mockDistDirectoryFileSystem(context)); | ||
|
||
await zip(context); | ||
|
||
const outDir = path.resolve(context.env.cwd, 'dist'); | ||
|
||
const platformDirsAndZips = platforms | ||
.map((platform) => { | ||
const zipFilename = expectedFilename.replace('[PLATFORM]', platform); | ||
|
||
return [`${platform}-test`, zipFilename]; | ||
}) | ||
.flat(); | ||
|
||
const outDirContents = await fs.promises.readdir(outDir); | ||
|
||
expect(outDirContents).toEqual(platformDirsAndZips); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters