chore: enhance preprocessor commands to automate releases. (#2446)

Last release v1.3.0 had an error in the documentation, claiming
it wasn't released.

This patch makes sure we have a little bit of automation in place
to save us from this in future.
This commit is contained in:
Andrey Lushnikov
2018-04-25 17:11:45 -07:00
committed by GitHub
parent 8fce3195d6
commit 6d19db4df1
4 changed files with 96 additions and 57 deletions

View File

@@ -17,7 +17,6 @@
const preprocessor = require('.');
const SourceFactory = require('../SourceFactory');
const factory = new SourceFactory();
const VERSION = require('../../../package.json').version;
const {TestRunner, Reporter, Matchers} = require('../../testrunner/');
const runner = new TestRunner();
@@ -30,8 +29,10 @@ const {expect} = new Matchers();
describe('preprocessor', function() {
it('should throw for unknown command', function() {
const source = factory.createForTest('doc.md', getCommand('unknownCommand()'));
const messages = preprocessor([source]);
const source = factory.createForTest('doc.md', `
<!-- gen:unknown-command -->something<!-- gen:stop -->
`);
const messages = preprocessor([source], '1.1.1');
expect(source.hasUpdatedText()).toBe(false);
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('error');
@@ -39,32 +40,85 @@ describe('preprocessor', function() {
});
describe('gen:version', function() {
it('should work', function() {
const source = factory.createForTest('doc.md', `Puppeteer v${getCommand('version')}`);
const messages = preprocessor([source]);
const source = factory.createForTest('doc.md', `
Puppeteer <!-- gen:version -->XXX<!-- gen:stop -->
`);
const messages = preprocessor([source], '1.2.0');
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('warning');
expect(messages[0].text).toContain('doc.md');
expect(source.text()).toBe(`Puppeteer v${getCommand('version', VERSION)}`);
expect(source.text()).toBe(`
Puppeteer <!-- gen:version -->v1.2.0<!-- gen:stop -->
`);
});
it('should work for *-post versions', function() {
const source = factory.createForTest('doc.md', `
Puppeteer <!-- gen:version -->XXX<!-- gen:stop -->
`);
const messages = preprocessor([source], '1.2.0-post');
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('warning');
expect(messages[0].text).toContain('doc.md');
expect(source.text()).toBe(`
Puppeteer <!-- gen:version -->Tip-Of-Tree<!-- gen:stop -->
`);
});
it('should tolerate different writing', function() {
const source = factory.createForTest('doc.md', `Puppeteer v<!-- gEn:version ( ) -->WHAT
const source = factory.createForTest('doc.md', `Puppeteer v<!-- gEn:version -->WHAT
<!-- GEN:stop -->`);
preprocessor([source]);
expect(source.text()).toBe(`Puppeteer v<!-- gEn:version ( ) -->${VERSION}<!-- GEN:stop -->`);
preprocessor([source], '1.1.1');
expect(source.text()).toBe(`Puppeteer v<!-- gEn:version -->v1.1.1<!-- GEN:stop -->`);
});
it('should not tolerate missing gen:stop', function() {
const source = factory.createForTest('doc.md', `<!--GEN:version-->`);
const messages = preprocessor([source]);
const messages = preprocessor([source], '1.2.0');
expect(source.hasUpdatedText()).toBe(false);
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('error');
expect(messages[0].text).toContain(`Failed to find 'gen:stop'`);
});
});
describe('gen:empty-if-release', function() {
it('should clear text when release version', function() {
const source = factory.createForTest('doc.md', `
<!-- gen:empty-if-release -->XXX<!-- gen:stop -->
`);
const messages = preprocessor([source], '1.1.1');
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('warning');
expect(messages[0].text).toContain('doc.md');
expect(source.text()).toBe(`
<!-- gen:empty-if-release --><!-- gen:stop -->
`);
});
it('should keep text when non-release version', function() {
const source = factory.createForTest('doc.md', `
<!-- gen:empty-if-release -->XXX<!-- gen:stop -->
`);
const messages = preprocessor([source], '1.1.1-post');
expect(messages.length).toBe(0);
expect(source.text()).toBe(`
<!-- gen:empty-if-release -->XXX<!-- gen:stop -->
`);
});
});
it('should work with multiple commands', function() {
const source = factory.createForTest('doc.md', `
<!-- gen:version -->XXX<!-- gen:stop -->
<!-- gen:empty-if-release -->YYY<!-- gen:stop -->
<!-- gen:version -->ZZZ<!-- gen:stop -->
`);
const messages = preprocessor([source], '1.1.1');
expect(messages.length).toBe(1);
expect(messages[0].type).toBe('warning');
expect(messages[0].text).toContain('doc.md');
expect(source.text()).toBe(`
<!-- gen:version -->v1.1.1<!-- gen:stop -->
<!-- gen:empty-if-release --><!-- gen:stop -->
<!-- gen:version -->v1.1.1<!-- gen:stop -->
`);
});
});
runner.run();
function getCommand(name, body = '') {
return `<!--gen:${name}-->${body}<!--gen:stop-->`;
}