2019-11-19 05:18:28 +03: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.
|
|
|
|
*/
|
|
|
|
|
2020-08-13 23:57:27 +03:00
|
|
|
const {runCommands} = require('.');
|
2019-11-19 05:18:28 +03:00
|
|
|
const Source = require('../Source');
|
2020-10-12 19:16:02 +03:00
|
|
|
const { folio } = require('folio');
|
|
|
|
const { describe, it, expect } = folio;
|
2019-11-19 05:18:28 +03:00
|
|
|
|
|
|
|
describe('runCommands', function() {
|
2020-02-14 05:26:38 +03:00
|
|
|
const OPTIONS_REL = {
|
|
|
|
libversion: '1.3.0',
|
|
|
|
chromiumVersion: '80.0.4004.0',
|
|
|
|
firefoxVersion: '73.0b3',
|
|
|
|
};
|
|
|
|
const OPTIONS_DEV = {
|
|
|
|
libversion: '1.3.0-post',
|
|
|
|
chromiumVersion: '<CRVERSION>',
|
|
|
|
firefoxVersion: '<FFVERSION>',
|
|
|
|
};
|
2019-11-19 05:18:28 +03:00
|
|
|
it('should throw for unknown command', function() {
|
|
|
|
const source = new Source('doc.md', `
|
|
|
|
<!-- gen:unknown-command -->something<!-- gen:stop -->
|
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.hasUpdatedText()).toBe(false);
|
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].type).toBe('error');
|
|
|
|
expect(messages[0].text).toContain('Unknown command');
|
|
|
|
});
|
|
|
|
describe('gen:version', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
const source = new Source('doc.md', `
|
|
|
|
Playwright <!-- gen:version -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.text()).toBe(`
|
2020-02-14 05:26:38 +03:00
|
|
|
Playwright <!-- gen:version -->v1.3.0<!-- gen:stop -->
|
2019-11-19 05:18:28 +03:00
|
|
|
`);
|
|
|
|
});
|
2020-04-22 08:08:56 +03:00
|
|
|
it('should work for pre-release versions', function() {
|
2019-11-19 05:18:28 +03:00
|
|
|
const source = new Source('doc.md', `
|
|
|
|
Playwright <!-- gen:version -->XXX<!-- gen:stop -->
|
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_DEV);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.text()).toBe(`
|
|
|
|
Playwright <!-- gen:version -->Tip-Of-Tree<!-- gen:stop -->
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
it('should tolerate different writing', function() {
|
|
|
|
const source = new Source('doc.md', `Playwright v<!-- gEn:version -->WHAT
|
|
|
|
<!-- GEN:stop -->`);
|
2020-02-14 05:26:38 +03:00
|
|
|
runCommands([source], OPTIONS_REL);
|
|
|
|
expect(source.text()).toBe(`Playwright v<!-- gEn:version -->v1.3.0<!-- GEN:stop -->`);
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
it('should not tolerate missing gen:stop', function() {
|
|
|
|
const source = new Source('doc.md', `<!--GEN:version-->`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2019-11-19 05:18:28 +03: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'`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('gen:toc', function() {
|
|
|
|
it('should work', () => {
|
|
|
|
const source = new Source('doc.md', `<!-- gen:toc -->XXX<!-- gen:stop -->
|
|
|
|
### class: page
|
|
|
|
#### page.$
|
|
|
|
#### page.$$`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.text()).toBe(`<!-- gen:toc -->
|
|
|
|
- [class: page](#class-page)
|
|
|
|
* [page.$](#page)
|
|
|
|
* [page.$$](#page-1)
|
|
|
|
<!-- gen:stop -->
|
|
|
|
### class: page
|
|
|
|
#### page.$
|
|
|
|
#### page.$$`);
|
|
|
|
});
|
|
|
|
it('should work with code blocks', () => {
|
|
|
|
const source = new Source('doc.md', `<!-- gen:toc -->XXX<!-- gen:stop -->
|
|
|
|
### class: page
|
|
|
|
|
|
|
|
\`\`\`bash
|
|
|
|
# yo comment
|
|
|
|
\`\`\`
|
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.text()).toBe(`<!-- gen:toc -->
|
|
|
|
- [class: page](#class-page)
|
|
|
|
<!-- gen:stop -->
|
|
|
|
### class: page
|
|
|
|
|
|
|
|
\`\`\`bash
|
|
|
|
# yo comment
|
|
|
|
\`\`\`
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
it('should work with links in titles', () => {
|
|
|
|
const source = new Source('doc.md', `<!-- gen:toc -->XXX<!-- gen:stop -->
|
|
|
|
### some [link](#foobar) here
|
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.text()).toBe(`<!-- gen:toc -->
|
|
|
|
- [some link here](#some-link-here)
|
|
|
|
<!-- gen:stop -->
|
|
|
|
### some [link](#foobar) here
|
|
|
|
`);
|
|
|
|
});
|
2020-01-22 23:21:45 +03:00
|
|
|
it('should be able to create sub-table-of-contents', () => {
|
|
|
|
const source = new Source('doc.md', `
|
|
|
|
## First
|
|
|
|
<!-- gen:toc -->XXX<!-- gen:stop -->
|
|
|
|
### first.1
|
|
|
|
### first.2
|
|
|
|
#### first.2.1
|
|
|
|
## Second
|
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2020-01-22 23:21:45 +03:00
|
|
|
expect(source.text()).toBe(`
|
|
|
|
## First
|
|
|
|
<!-- gen:toc -->
|
|
|
|
- [first.1](#first1)
|
|
|
|
- [first.2](#first2)
|
|
|
|
* [first.2.1](#first21)
|
|
|
|
<!-- gen:stop -->
|
|
|
|
### first.1
|
|
|
|
### first.2
|
|
|
|
#### first.2.1
|
|
|
|
## Second
|
|
|
|
`);
|
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
it('should work with multiple commands', function() {
|
|
|
|
const source = new Source('doc.md', `
|
2020-02-14 05:26:38 +03:00
|
|
|
<!-- gen:version -->xxx<!-- gen:stop -->
|
|
|
|
<!-- gen:version -->zzz<!-- gen:stop -->
|
2019-11-19 05:18:28 +03:00
|
|
|
`);
|
2020-02-14 05:26:38 +03:00
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(source.text()).toBe(`
|
2020-02-14 05:26:38 +03:00
|
|
|
<!-- gen:version -->v1.3.0<!-- gen:stop -->
|
|
|
|
<!-- gen:version -->v1.3.0<!-- gen:stop -->
|
2019-11-19 05:18:28 +03:00
|
|
|
`);
|
|
|
|
});
|
2020-04-22 08:08:56 +03:00
|
|
|
describe('gen:chromium-version', function() {
|
|
|
|
it('should work', function() {
|
2020-02-14 05:26:38 +03:00
|
|
|
const source = new Source('doc.md', `
|
2020-04-22 08:08:56 +03:00
|
|
|
Playwright <!-- gen:chromium-version -->XXX<!-- gen:stop -->
|
2020-02-14 05:26:38 +03:00
|
|
|
`);
|
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2020-02-14 05:26:38 +03:00
|
|
|
expect(source.text()).toBe(`
|
2020-04-22 08:08:56 +03:00
|
|
|
Playwright <!-- gen:chromium-version -->80.0.4004.0<!-- gen:stop -->
|
2020-02-14 05:26:38 +03:00
|
|
|
`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('gen:firefox-version', function() {
|
2020-04-22 08:08:56 +03:00
|
|
|
it('should work', function() {
|
2020-02-14 05:26:38 +03:00
|
|
|
const source = new Source('doc.md', `
|
2020-04-22 08:08:56 +03:00
|
|
|
Playwright <!-- gen:firefox-version -->XXX<!-- gen:stop -->
|
2020-02-14 05:26:38 +03:00
|
|
|
`);
|
|
|
|
const messages = runCommands([source], OPTIONS_REL);
|
2020-04-24 05:52:06 +03:00
|
|
|
expect(messages.length).toBe(0);
|
|
|
|
expect(source.hasUpdatedText()).toBe(true);
|
2020-02-14 05:26:38 +03:00
|
|
|
expect(source.text()).toBe(`
|
2020-04-22 08:08:56 +03:00
|
|
|
Playwright <!-- gen:firefox-version -->73.0b3<!-- gen:stop -->
|
2020-02-14 05:26:38 +03:00
|
|
|
`);
|
|
|
|
});
|
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
|