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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const preprocessor = require('.');
|
|
|
|
const SourceFactory = require('../SourceFactory');
|
|
|
|
const factory = new SourceFactory();
|
|
|
|
const VERSION = require('../../../package.json').version;
|
|
|
|
|
|
|
|
describe('preprocessor', function() {
|
2017-07-31 10:23:29 +00:00
|
|
|
it('should throw for unknown command', function() {
|
2017-08-21 23:39:04 +00:00
|
|
|
const source = factory.createForTest('doc.md', getCommand('unknownCommand()'));
|
|
|
|
const messages = preprocessor([source]);
|
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() {
|
2017-08-21 23:39:04 +00:00
|
|
|
const source = factory.createForTest('doc.md', `Puppeteer v${getCommand('version')}`);
|
|
|
|
const messages = preprocessor([source]);
|
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');
|
2017-07-31 10:23:29 +00:00
|
|
|
expect(source.text()).toBe(`Puppeteer v${getCommand('version', VERSION)}`);
|
2017-07-31 08:14:19 +00:00
|
|
|
});
|
|
|
|
it('should tolerate different writing', function() {
|
2017-08-21 23:39:04 +00:00
|
|
|
const source = factory.createForTest('doc.md', `Puppeteer v<!-- gEn:version ( ) -->WHAT
|
2017-07-31 08:14:19 +00:00
|
|
|
<!-- GEN:stop -->`);
|
|
|
|
preprocessor([source]);
|
|
|
|
expect(source.text()).toBe(`Puppeteer v<!-- gEn:version ( ) -->${VERSION}<!-- GEN:stop -->`);
|
|
|
|
});
|
|
|
|
it('should not tolerate missing gen:stop', function() {
|
2017-08-21 23:39:04 +00:00
|
|
|
const source = factory.createForTest('doc.md', `<!--GEN:version-->`);
|
|
|
|
const messages = preprocessor([source]);
|
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'`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-31 10:23:29 +00:00
|
|
|
function getCommand(name, body = '') {
|
|
|
|
return `<!--gen:${name}-->${body}<!--gen:stop-->`;
|
|
|
|
}
|