|
| 1 | +import fs from 'fs'; |
| 2 | +import TOML from 'smol-toml'; |
1 | 3 | import { describe, expect, test } from 'vitest';
|
2 | 4 | import {
|
3 | 5 | bDistPackage,
|
@@ -52,13 +54,65 @@ test('prepare: setVersionPy', async () => {
|
52 | 54 | );
|
53 | 55 | });
|
54 | 56 |
|
55 |
| -test('prepare: setVersionToml', async () => { |
56 |
| - const { config, context } = genPackage({ |
57 |
| - legacyInterface: false, |
58 |
| - }); |
59 |
| - await expect( |
60 |
| - setVersionToml(config.srcDir, '2.0.0', pipe(context)), |
61 |
| - ).resolves.toBe(undefined); |
| 57 | +describe('prepare: setVersionToml', async () => { |
| 58 | + const testCases = [ |
| 59 | + { |
| 60 | + name: 'version in project', |
| 61 | + section: 'project', |
| 62 | + content: `[project] |
| 63 | +version = "0.0.0"`, |
| 64 | + }, |
| 65 | + { |
| 66 | + name: 'no version', |
| 67 | + section: 'project', |
| 68 | + content: `[project] |
| 69 | +name = "test"`, |
| 70 | + }, |
| 71 | + { |
| 72 | + name: 'poetry: version in tool.poetry', |
| 73 | + section: 'tool.poetry', |
| 74 | + content: `[tool.poetry] |
| 75 | +version = "0.0.0"`, |
| 76 | + }, |
| 77 | + { |
| 78 | + name: 'poetry: version in project', |
| 79 | + section: 'project', |
| 80 | + content: `[project] |
| 81 | +version = "0.0.0" |
| 82 | +
|
| 83 | +[tool.poetry] |
| 84 | +name = "test" |
| 85 | +
|
| 86 | +[tool.poetry.dependencies] |
| 87 | +python = "^3.7"`, |
| 88 | + }, |
| 89 | + ]; |
| 90 | + |
| 91 | + for (const t of testCases) { |
| 92 | + test( |
| 93 | + t.name, |
| 94 | + async () => { |
| 95 | + const { config, context } = genPackage({ |
| 96 | + legacyInterface: false, |
| 97 | + content: t.content, |
| 98 | + }); |
| 99 | + await expect( |
| 100 | + setVersionToml(config.srcDir, '1.0.0', pipe(context)), |
| 101 | + ).resolves.toBe(undefined); |
| 102 | + |
| 103 | + const toml = fs.readFileSync(config.pyprojectPath, { |
| 104 | + encoding: 'utf8', |
| 105 | + }); |
| 106 | + const pyproject: any = TOML.parse(toml); |
| 107 | + const version = t.section |
| 108 | + .split('.') |
| 109 | + .reduce((acc, key) => acc[key], pyproject).version; |
| 110 | + |
| 111 | + await expect(version).toBe('1.0.0'); |
| 112 | + }, |
| 113 | + 60000, |
| 114 | + ); |
| 115 | + } |
62 | 116 | });
|
63 | 117 |
|
64 | 118 | test('prepare: versionCmd', async () => {
|
|
0 commit comments