|
1 |
| -import { PassThrough } from 'stream'; |
2 | 1 | import { expect, test } from 'vitest';
|
3 | 2 | import { prepare, publish, verifyConditions } from '../lib/index.js';
|
4 |
| -import { genPackage, hasPackage } from './util.js'; |
5 |
| - |
6 |
| -class EndlessPassThrough extends PassThrough { |
7 |
| - end(): this { |
8 |
| - return this; |
9 |
| - } |
10 |
| - close() { |
11 |
| - super.end(); |
12 |
| - } |
13 |
| -} |
| 3 | +import { genPackage, hasPackage, OutputAnalyzer } from './util.js'; |
14 | 4 |
|
15 | 5 | test('test semantic-release-pypi (pyproject.toml)', async () => {
|
16 | 6 | if (!process.env['TESTPYPI_TOKEN']) {
|
@@ -78,26 +68,52 @@ build-backend = "poetry.core.masonry.api"`;
|
78 | 68 | },
|
79 | 69 | });
|
80 | 70 |
|
81 |
| - const stream = new EndlessPassThrough(); |
82 |
| - context.stdout = stream; |
83 |
| - |
84 |
| - let built = false; |
85 |
| - stream.on('data', (bytes) => { |
86 |
| - const str = bytes.toString('utf-8'); |
87 |
| - if ( |
88 |
| - str.includes('Successfully built') && |
89 |
| - str.includes('poetry_demo-1.0.0') |
90 |
| - ) { |
91 |
| - built = true; |
92 |
| - } |
| 71 | + const outputAnalyzer = new OutputAnalyzer({ |
| 72 | + built: ['Successfully built', 'poetry_demo-1.0.0'], |
93 | 73 | });
|
| 74 | + context.stdout = outputAnalyzer.stream; |
94 | 75 |
|
95 | 76 | await verifyConditions(config, context);
|
96 | 77 | await prepare(config, context);
|
97 | 78 | await publish(config, context);
|
98 | 79 |
|
99 |
| - expect(built).toEqual(true); |
| 80 | + expect(outputAnalyzer.res.built).toEqual(true); |
100 | 81 | expect(context.logger.log).toHaveBeenCalledWith(
|
101 | 82 | 'Not publishing package due to requested configuration',
|
102 | 83 | );
|
103 | 84 | }, 60000);
|
| 85 | + |
| 86 | +test('semantic-release-pypi (hatch, dynamic version)', async () => { |
| 87 | + const pyproject = `[project] |
| 88 | +name = "hatch-demo" |
| 89 | +dynamic = ["version"] |
| 90 | +
|
| 91 | +[build-system] |
| 92 | +requires = ["hatchling"] |
| 93 | +build-backend = "hatchling.build" |
| 94 | +
|
| 95 | +[tool.hatch.version] |
| 96 | +path = "hatch_demo/__init__.py"`; |
| 97 | + |
| 98 | + const { config, context } = await genPackage({ |
| 99 | + legacyInterface: false, |
| 100 | + config: { pypiPublish: false, versionCmd: 'hatch version ${version}' }, |
| 101 | + content: pyproject, |
| 102 | + files: { |
| 103 | + hatch_demo: { |
| 104 | + '__init__.py': '__version__ = "0.0.0"\n', |
| 105 | + }, |
| 106 | + }, |
| 107 | + }); |
| 108 | + |
| 109 | + const outputAnalyzer = new OutputAnalyzer({ |
| 110 | + built: ['Successfully built', 'hatch_demo-1.0.0'], |
| 111 | + }); |
| 112 | + context.stdout = outputAnalyzer.stream; |
| 113 | + |
| 114 | + await verifyConditions(config, context); |
| 115 | + await prepare(config, context); |
| 116 | + await publish(config, context); |
| 117 | + |
| 118 | + expect(outputAnalyzer.res.built).toEqual(true); |
| 119 | +}, 60000); |
0 commit comments