Skip to content
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"fix": "pnpm lint --fix",
"test": "vitest run",
"test:watch": "vitest",
"typecheck": "tsc --noEmit",
"docs:dev": "cd docs && pnpm dev",
"docs:build": "cd docs && pnpm build"
},
Expand Down
34 changes: 26 additions & 8 deletions src/targets/__tests__/pypi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { PypiTarget } from '../pypi';
import { NoneArtifactProvider } from '../../artifact_providers/none';
import { RemoteArtifact } from '../../artifact_providers/base';

vi.mock('../../utils/system', async (importOriginal) => {
vi.mock('../../utils/system', async importOriginal => {
const actual = await importOriginal<typeof import('../../utils/system')>();
return {
...actual,
checkExecutableIsPresent: vi.fn(),
spawnProcess: vi.fn(),
};
});

import { spawnProcess } from '../../utils/system';

describe('pypi', () => {
const oldEnv = { ...process.env };

Expand All @@ -25,16 +28,18 @@ describe('pypi', () => {

test('it uploads all artifacts in a single twine call', async () => {
const target = new PypiTarget({ name: 'pypi' }, new NoneArtifactProvider());
target.getArtifactsForRevision = vi.fn().mockResolvedValueOnce([
{ filename: 'pkg-1-py3-none-macos_11_0_arm64.whl' },
{ filename: 'pkg-1-py3-none-manylinux_2_17_x86_64.whl' },
{ filename: 'pkg-1.tar.gz' },
]);
target.getArtifactsForRevision = vi
.fn()
.mockResolvedValueOnce([
{ filename: 'pkg-1-py3-none-macos_11_0_arm64.whl' },
{ filename: 'pkg-1-py3-none-manylinux_2_17_x86_64.whl' },
{ filename: 'pkg-1.tar.gz' },
]);
target.artifactProvider.downloadArtifact = vi.fn(
async (
artifact: RemoteArtifact,
_downloadDirectory?: string | undefined
) => `downloaded/path/${artifact.filename}`
_downloadDirectory?: string | undefined,
) => `downloaded/path/${artifact.filename}`,
);
const upload = vi.fn();
target.uploadAssets = upload;
Expand All @@ -47,4 +52,17 @@ describe('pypi', () => {
'downloaded/path/pkg-1.tar.gz',
]);
});

test('uploadAssets calls twine with correct arguments', async () => {
vi.mocked(spawnProcess).mockResolvedValueOnce(Buffer.from(''));

const target = new PypiTarget({ name: 'pypi' }, new NoneArtifactProvider());
await target.uploadAssets(['/path/to/pkg.whl', '/path/to/pkg.tar.gz']);

expect(spawnProcess).toHaveBeenCalledWith('twine', [
'upload',
'/path/to/pkg.whl',
'/path/to/pkg.tar.gz',
]);
});
});
1 change: 1 addition & 0 deletions src/targets/crates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
checkExecutableIsPresent,
resolveExecutable,
runWithExecutable,
spawnProcess,
} from '../utils/system';
import { BaseTarget } from './base';
import { BaseArtifactProvider } from '../artifact_providers/base';
Expand Down
6 changes: 5 additions & 1 deletion src/targets/pypi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
RemoteArtifact,
} from '../artifact_providers/base';
import { ConfigurationError, reportError } from '../utils/errors';
import { checkExecutableIsPresent, runWithExecutable } from '../utils/system';
import {
checkExecutableIsPresent,
runWithExecutable,
spawnProcess,
} from '../utils/system';
import { BaseTarget } from './base';
import { logger } from '../logger';

Expand Down
Loading