/** * 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 {runCommands, ensureTipOfTreeAPILinks} = require('.'); const Source = require('../Source'); const TestRunner = require('../../testrunner/'); const runner = new TestRunner(); const {describe, xdescribe, fdescribe} = runner.api(); const {it, fit, xit} = runner.api(); const {beforeAll, beforeEach, afterAll, afterEach} = runner.api(); const {expect} = runner.api(); describe('runCommands', function() { const OPTIONS_REL = { libversion: '1.3.0', chromiumVersion: '80.0.4004.0', firefoxVersion: '73.0b3', }; const OPTIONS_DEV = { libversion: '1.3.0-post', chromiumVersion: '', firefoxVersion: '', }; it('should throw for unknown command', function() { const source = new Source('doc.md', ` something `); const messages = runCommands([source], OPTIONS_REL); 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 XXX `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` Playwright v1.3.0 `); }); it('should work for pre-release versions', function() { const source = new Source('doc.md', ` Playwright XXX `); const messages = runCommands([source], OPTIONS_DEV); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` Playwright Tip-Of-Tree `); }); it('should tolerate different writing', function() { const source = new Source('doc.md', `Playwright vWHAT `); runCommands([source], OPTIONS_REL); expect(source.text()).toBe(`Playwright vv1.3.0`); }); it('should not tolerate missing gen:stop', function() { const source = new Source('doc.md', ``); const messages = runCommands([source], OPTIONS_REL); 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', `XXX ### class: page #### page.$ #### page.$$`); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` - [class: page](#class-page) * [page.$](#page) * [page.$$](#page-1) ### class: page #### page.$ #### page.$$`); }); it('should work with code blocks', () => { const source = new Source('doc.md', `XXX ### class: page \`\`\`bash # yo comment \`\`\` `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` - [class: page](#class-page) ### class: page \`\`\`bash # yo comment \`\`\` `); }); it('should work with links in titles', () => { const source = new Source('doc.md', `XXX ### some [link](#foobar) here `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` - [some link here](#some-link-here) ### some [link](#foobar) here `); }); it('should be able to create sub-table-of-contents', () => { const source = new Source('doc.md', ` ## First XXX ### first.1 ### first.2 #### first.2.1 ## Second `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` ## First - [first.1](#first1) - [first.2](#first2) * [first.2.1](#first21) ### first.1 ### first.2 #### first.2.1 ## Second `); }); }); it('should work with multiple commands', function() { const source = new Source('doc.md', ` xxx zzz `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` v1.3.0 v1.3.0 `); }); describe('gen:chromium-version', function() { it('should work', function() { const source = new Source('doc.md', ` Playwright XXX `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` Playwright 80.0.4004.0 `); }); }); describe('gen:firefox-version', function() { it('should work', function() { const source = new Source('doc.md', ` Playwright XXX `); const messages = runCommands([source], OPTIONS_REL); expect(messages.length).toBe(1); expect(messages[0].type).toBe('warning'); expect(messages[0].text).toContain('doc.md'); expect(source.text()).toBe(` Playwright 73.0b3 `); }); }); }); runner.run();