Skip to content

Commit

Permalink
add tests for updating version in composer updater
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Jan 26, 2024
1 parent 2c32762 commit 5093438
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions __snapshots__/root-composer-update-packages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
exports['composer-update-package.json updateContent does not update version in composer if it does not exist 1'] = `
{}
`

exports['composer-update-package.json updateContent updates all versions in root composer file 1'] = `
{
"name": "google/cloud",
Expand Down Expand Up @@ -256,3 +260,7 @@ exports['composer-update-package.json updateContent updates all versions in root
}
`

exports['composer-update-package.json updateContent updates version in composer if it exists 1'] = `
{"version":"1.0.0"}
`
21 changes: 21 additions & 0 deletions test/updaters/root-composer-update-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {readFileSync} from 'fs';
import {resolve} from 'path';
import * as snapshot from 'snap-shot-it';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {RootComposerUpdatePackages} from '../../src/updaters/php/root-composer-update-packages';
import {Version} from '../../src/version';

Expand All @@ -38,5 +39,25 @@ describe('composer-update-package.json', () => {
const newContent = composer.updateContent(oldContent);
snapshot(newContent);
});
it('updates version in composer if it exists', async () => {
const composer = new RootComposerUpdatePackages({
version: Version.parse('1.0.0'),
});
const newContent = composer.updateContent(

Check failure on line 46 in test/updaters/root-composer-update-packages.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········'{"version":·"0.8.0"}'⏎······` with `'{"version":·"0.8.0"}'`
'{"version": "0.8.0"}'
);
expect(newContent).to.eql('{"version":"1.0.0"}');
snapshot(newContent);
});
it('does not update version in composer if it does not exist', async () => {
const composer = new RootComposerUpdatePackages({
version: Version.parse('1.0.0'),
});
const newContent = composer.updateContent(

Check failure on line 56 in test/updaters/root-composer-update-packages.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········'{}'⏎······` with `'{}'`
'{}'
);
expect(newContent).to.eql('{}');
snapshot(newContent);
});
});
});

0 comments on commit 5093438

Please sign in to comment.