2017-07-31 08:14:19 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-08-09 01:20:20 +00:00
|
|
|
const {runCommands, ensureReleasedAPILinks} = require('.');
|
2018-04-26 01:07:20 +00:00
|
|
|
const Source = require('../Source');
|
2017-12-08 00:37:22 +00:00
|
|
|
const {TestRunner, Reporter, Matchers} = require('../../testrunner/');
|
|
|
|
const runner = new TestRunner();
|
|
|
|
new Reporter(runner);
|
|
|
|
|
|
|
|
const {describe, xdescribe, fdescribe} = runner;
|
|
|
|
const {it, fit, xit} = runner;
|
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = runner;
|
|
|
|
const {expect} = new Matchers();
|
|
|
|
|
2018-08-09 01:20:20 +00:00
|
|
|
describe('ensureReleasedAPILinks', function() {
|
|
|
|
it('should work with non-release version', function() {
|
|
|
|
const source = new Source('doc.md', `
|
2018-09-05 19:33:04 +00:00
|
|
|
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.1.0/docs/api.md#class-page)
|
2018-08-09 01:20:20 +00:00
|
|
|
`);
|
|
|
|
const messages = ensureReleasedAPILinks([source], '1.3.0-post');
|
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].type).toBe('warning');
|
|
|
|
expect(messages[0].text).toContain('doc.md');
|
|
|
|
expect(source.text()).toBe(`
|
|
|
|
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.3.0/docs/api.md#class-page)
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
it('should work with release version', function() {
|
|
|
|
const source = new Source('doc.md', `
|
2018-09-05 19:33:04 +00:00
|
|
|
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.1.0/docs/api.md#class-page)
|
2018-08-09 01:20:20 +00:00
|
|
|
`);
|
|
|
|
const messages = ensureReleasedAPILinks([source], '1.3.0');
|
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].type).toBe('warning');
|
|
|
|
expect(messages[0].text).toContain('doc.md');
|
|
|
|
expect(source.text()).toBe(`
|
|
|
|
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.3.0/docs/api.md#class-page)
|
|
|
|
`);
|
|
|
|
});
|
2018-09-05 19:33:04 +00:00
|
|
|
it('should keep master links intact', function() {
|
|
|
|
const source = new Source('doc.md', `
|
|
|
|
[API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page)
|
|
|
|
`);
|
|
|
|
const messages = ensureReleasedAPILinks([source], '1.3.0');
|
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.text()).toBe(`
|
|
|
|
[API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page)
|
|
|
|
`);
|
|
|
|
});
|
2018-08-09 01:20:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('runCommands', function() {
|
2017-07-31 10:23:29 +00:00
|
|
|
it('should throw for unknown command', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `
|
2018-04-26 00:11:45 +00:00
|
|
|
<!-- gen:unknown-command -->something<!-- gen:stop -->
|
|
|
|
`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.1.1');
|
2017-07-31 10:23:29 +00:00
|
|
|
expect(source.hasUpdatedText()).toBe(false);
|
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].type).toBe('error');
|
|
|
|
expect(messages[0].text).toContain('Unknown command');
|
|
|
|
});
|
2017-07-31 08:14:19 +00:00
|
|
|
describe('gen:version', function() {
|
|
|
|
it('should work', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `
|
2018-04-26 00:11:45 +00:00
|
|
|
Puppeteer <!-- gen:version -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.2.0');
|
2017-07-31 08:14:19 +00:00
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].type).toBe('warning');
|
|
|
|
expect(messages[0].text).toContain('doc.md');
|
2018-04-26 00:11:45 +00:00
|
|
|
expect(source.text()).toBe(`
|
|
|
|
Puppeteer <!-- gen:version -->v1.2.0<!-- gen:stop -->
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
it('should work for *-post versions', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `
|
2018-04-26 00:11:45 +00:00
|
|
|
Puppeteer <!-- gen:version -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.2.0-post');
|
2018-04-26 00:11:45 +00:00
|
|
|
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 -->
|
|
|
|
`);
|
2017-07-31 08:14:19 +00:00
|
|
|
});
|
|
|
|
it('should tolerate different writing', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `Puppeteer v<!-- gEn:version -->WHAT
|
2017-07-31 08:14:19 +00:00
|
|
|
<!-- GEN:stop -->`);
|
2018-08-09 01:20:20 +00:00
|
|
|
runCommands([source], '1.1.1');
|
2018-04-26 00:11:45 +00:00
|
|
|
expect(source.text()).toBe(`Puppeteer v<!-- gEn:version -->v1.1.1<!-- GEN:stop -->`);
|
2017-07-31 08:14:19 +00:00
|
|
|
});
|
|
|
|
it('should not tolerate missing gen:stop', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `<!--GEN:version-->`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.2.0');
|
2017-07-31 08:14:19 +00:00
|
|
|
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'`);
|
|
|
|
});
|
|
|
|
});
|
2018-04-26 00:11:45 +00:00
|
|
|
describe('gen:empty-if-release', function() {
|
|
|
|
it('should clear text when release version', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `
|
2018-04-26 00:11:45 +00:00
|
|
|
<!-- gen:empty-if-release -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.1.1');
|
2018-04-26 00:11:45 +00:00
|
|
|
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() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `
|
2018-04-26 00:11:45 +00:00
|
|
|
<!-- gen:empty-if-release -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.1.1-post');
|
2018-04-26 00:11:45 +00:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.text()).toBe(`
|
|
|
|
<!-- gen:empty-if-release -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
});
|
2018-05-31 21:21:43 +00:00
|
|
|
describe('gen:toc', function() {
|
|
|
|
it('should work', () => {
|
|
|
|
const source = new Source('doc.md', `<!-- gen:toc -->XXX<!-- gen:stop -->
|
|
|
|
### class: page
|
|
|
|
#### page.$
|
|
|
|
#### page.$$`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.3.0');
|
2018-05-31 21:21:43 +00:00
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].type).toBe('warning');
|
|
|
|
expect(messages[0].text).toContain('doc.md');
|
|
|
|
expect(source.text()).toBe(`<!-- gen:toc -->
|
|
|
|
- [class: page](#class-page)
|
|
|
|
* [page.$](#page)
|
|
|
|
* [page.$$](#page-1)
|
|
|
|
<!-- gen:stop -->
|
|
|
|
### class: page
|
|
|
|
#### page.$
|
|
|
|
#### page.$$`);
|
|
|
|
});
|
|
|
|
});
|
2018-04-26 00:11:45 +00:00
|
|
|
it('should work with multiple commands', function() {
|
2018-04-26 01:07:20 +00:00
|
|
|
const source = new Source('doc.md', `
|
2018-04-26 00:11:45 +00:00
|
|
|
<!-- gen:version -->XXX<!-- gen:stop -->
|
|
|
|
<!-- gen:empty-if-release -->YYY<!-- gen:stop -->
|
|
|
|
<!-- gen:version -->ZZZ<!-- gen:stop -->
|
|
|
|
`);
|
2018-08-09 01:20:20 +00:00
|
|
|
const messages = runCommands([source], '1.1.1');
|
2018-04-26 00:11:45 +00:00
|
|
|
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 -->
|
|
|
|
`);
|
|
|
|
});
|
2017-07-31 08:14:19 +00:00
|
|
|
});
|
|
|
|
|
2017-12-08 00:37:22 +00:00
|
|
|
runner.run();
|
|
|
|
|