diff --git a/lib/tasks/verify-readme.js b/lib/tasks/verify-readme.js index 086a7f8a..28b6b8fb 100644 --- a/lib/tasks/verify-readme.js +++ b/lib/tasks/verify-readme.js @@ -16,12 +16,16 @@ const log = require('../helpers/log'); async function origamiJson(config) { // Error if there is no readme to verify. - const readmePath = path.join(config.cwd, '/README.md'); - const hasReadme = await fs.exists(readmePath); - if (!hasReadme) { + const uppercaseReadmePath = path.join(config.cwd, '/README.md'); + const hasUppercaseReadme = await fs.exists(uppercaseReadmePath); + const lowercaseReadmePath = path.join(config.cwd, '/readme.md'); + const hasLowercaseReadme = await fs.exists(lowercaseReadmePath); + if (!hasUppercaseReadme && !hasLowercaseReadme) { throw new Error('Components require a README.md with documentation.'); } + const readmePath = hasUppercaseReadme ? uppercaseReadmePath : lowercaseReadmePath; + const contents = await readFile(readmePath, { encoding: 'utf-8', }); diff --git a/test/integration/verify/fixtures/readme/README.md b/test/integration/verify/fixtures/readme-invalid-name/ReadmE.md similarity index 100% rename from test/integration/verify/fixtures/readme/README.md rename to test/integration/verify/fixtures/readme-invalid-name/ReadmE.md diff --git a/test/integration/verify/fixtures/readme/bower.json b/test/integration/verify/fixtures/readme-invalid-name/bower.json similarity index 100% rename from test/integration/verify/fixtures/readme/bower.json rename to test/integration/verify/fixtures/readme-invalid-name/bower.json diff --git a/test/integration/verify/fixtures/readme/main.js b/test/integration/verify/fixtures/readme-invalid-name/main.js similarity index 100% rename from test/integration/verify/fixtures/readme/main.js rename to test/integration/verify/fixtures/readme-invalid-name/main.js diff --git a/test/integration/verify/fixtures/readme/main.scss b/test/integration/verify/fixtures/readme-invalid-name/main.scss similarity index 100% rename from test/integration/verify/fixtures/readme/main.scss rename to test/integration/verify/fixtures/readme-invalid-name/main.scss diff --git a/test/integration/verify/fixtures/readme/origami.json b/test/integration/verify/fixtures/readme-invalid-name/origami.json similarity index 100% rename from test/integration/verify/fixtures/readme/origami.json rename to test/integration/verify/fixtures/readme-invalid-name/origami.json diff --git a/test/integration/verify/fixtures/readme-valid-lowercase/bower.json b/test/integration/verify/fixtures/readme-valid-lowercase/bower.json new file mode 100644 index 00000000..5141cf8e --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-lowercase/bower.json @@ -0,0 +1,5 @@ +{ + "name": "test-component", + "main": [], + "dependencies": {} +} diff --git a/test/integration/verify/fixtures/readme-valid-lowercase/main.js b/test/integration/verify/fixtures/readme-valid-lowercase/main.js new file mode 100644 index 00000000..6b6afbe0 --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-lowercase/main.js @@ -0,0 +1,2 @@ +const a = 10 ** 2; +self.world = a; diff --git a/test/integration/verify/fixtures/readme-valid-lowercase/main.scss b/test/integration/verify/fixtures/readme-valid-lowercase/main.scss new file mode 100644 index 00000000..df006bf3 --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-lowercase/main.scss @@ -0,0 +1,12 @@ +@mixin oTestComponent() { + .o-test { + font-size: 18px; + + &--error { + background-color: red; + color: white; + } + } +} + +@include oTestComponent; diff --git a/test/integration/verify/fixtures/readme-valid-lowercase/origami.json b/test/integration/verify/fixtures/readme-valid-lowercase/origami.json new file mode 100644 index 00000000..4e3c7dad --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-lowercase/origami.json @@ -0,0 +1,22 @@ +{ + "description": "for a fixture", + "keywords": [], + "origamiType": "module", + "origamiCategory": "components", + "origamiVersion": 1, + "brands": [], + "support": "https://github.com/Financial-Times/o-example/issues", + "supportContact": { + "email": "origami.support@ft.com", + "slack": "financialtimes/#origami-support" + }, + "supportStatus": "experimental", + "browserFeatures": {}, + "demosDefaults": { + + + "documentClasses": "", + "dependencies": [] + }, + "demos": [] +} diff --git a/test/integration/verify/fixtures/readme-valid-lowercase/readme.md b/test/integration/verify/fixtures/readme-valid-lowercase/readme.md new file mode 100644 index 00000000..956e34d6 --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-lowercase/readme.md @@ -0,0 +1,7 @@ +# test-component + +test component + +## Licence + +MIT diff --git a/test/integration/verify/fixtures/readme-valid-uppercase/README.md b/test/integration/verify/fixtures/readme-valid-uppercase/README.md new file mode 100644 index 00000000..956e34d6 --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-uppercase/README.md @@ -0,0 +1,7 @@ +# test-component + +test component + +## Licence + +MIT diff --git a/test/integration/verify/fixtures/readme-valid-uppercase/bower.json b/test/integration/verify/fixtures/readme-valid-uppercase/bower.json new file mode 100644 index 00000000..5141cf8e --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-uppercase/bower.json @@ -0,0 +1,5 @@ +{ + "name": "test-component", + "main": [], + "dependencies": {} +} diff --git a/test/integration/verify/fixtures/readme-valid-uppercase/main.js b/test/integration/verify/fixtures/readme-valid-uppercase/main.js new file mode 100644 index 00000000..6b6afbe0 --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-uppercase/main.js @@ -0,0 +1,2 @@ +const a = 10 ** 2; +self.world = a; diff --git a/test/integration/verify/fixtures/readme-valid-uppercase/main.scss b/test/integration/verify/fixtures/readme-valid-uppercase/main.scss new file mode 100644 index 00000000..df006bf3 --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-uppercase/main.scss @@ -0,0 +1,12 @@ +@mixin oTestComponent() { + .o-test { + font-size: 18px; + + &--error { + background-color: red; + color: white; + } + } +} + +@include oTestComponent; diff --git a/test/integration/verify/fixtures/readme-valid-uppercase/origami.json b/test/integration/verify/fixtures/readme-valid-uppercase/origami.json new file mode 100644 index 00000000..4e3c7dad --- /dev/null +++ b/test/integration/verify/fixtures/readme-valid-uppercase/origami.json @@ -0,0 +1,22 @@ +{ + "description": "for a fixture", + "keywords": [], + "origamiType": "module", + "origamiCategory": "components", + "origamiVersion": 1, + "brands": [], + "support": "https://github.com/Financial-Times/o-example/issues", + "supportContact": { + "email": "origami.support@ft.com", + "slack": "financialtimes/#origami-support" + }, + "supportStatus": "experimental", + "browserFeatures": {}, + "demosDefaults": { + + + "documentClasses": "", + "dependencies": [] + }, + "demos": [] +} diff --git a/test/integration/verify/verify.test.js b/test/integration/verify/verify.test.js index 822cf03c..030f28c9 100644 --- a/test/integration/verify/verify.test.js +++ b/test/integration/verify/verify.test.js @@ -7,6 +7,11 @@ const process = require('process'); const proclaim = require('proclaim'); const obtBinPath = require('../helpers/obtpath'); const rimraf = require('../helpers/delete'); +const fs = require('fs'); +const { promisify } = require('util'); +const mkdtemp = promisify(fs.mkdtemp); +const writeFile = promisify(fs.writeFile); +const os = require('os'); describe('obt verify', function () { @@ -65,6 +70,41 @@ describe('obt verify', function () { }); }); + describe('component with an invalid readme filename', function () { + + beforeEach(function () { + // Change the current working directory to the folder which contains the project we are testing against. + // We are doing this to replicate how obt is used when executed inside a terminal. + process.chdir(path.join(__dirname, '/fixtures/readme-invalid-name')); + }); + + afterEach(function () { + // Change the current working directory back to the directory where you started running these tests from. + process.chdir(process.cwd()); + }); + + + it('should error', async function () { + const folder = await mkdtemp(path.join(os.tmpdir(), 'foo-')); + const filePath = path.join(folder, 'testFilesystemCaseSensitivity.txt'); + await writeFile(path.join(folder, 'testFilesystemCaseSensitivity.txt'), "hello", "utf8"); + const caseSensitiveFileSystem = fs.existsSync(filePath.toUpperCase()); + // Do not run this test on case-insensitive filesystems because it will fail. + if (!caseSensitiveFileSystem) { + return obtBinPath() + .then(obt => { + return execa(obt, ['verify']); + }) + .then(() => { + throw new Error('obt verify should error.'); + }, output => { + // obt verify exited with a non-zero exit code, which is what we expected. + proclaim.include(output.stdout, 'Components require a README.md with documentation.'); + }); + } + }); + }); + describe('component with custom .remarkrc.js configuration', function () { beforeEach(function () { @@ -85,6 +125,48 @@ describe('obt verify', function () { }); }); }); + + describe('component with valid readme with lowercased name', function () { + + beforeEach(function () { + // Change the current working directory to the folder which contains the project we are testing against. + // We are doing this to replicate how obt is used when executed inside a terminal. + process.chdir(path.join(__dirname, '/fixtures/readme-valid-lowercase')); + }); + + afterEach(function () { + // Change the current working directory back to the directory where you started running these tests from. + process.chdir(process.cwd()); + }); + + it('should not error', function () { + return obtBinPath() + .then(obt => { + return execa(obt, ['verify']); + }); + }); + }); + + describe('component with valid readme with uppercased name', function () { + + beforeEach(function () { + // Change the current working directory to the folder which contains the project we are testing against. + // We are doing this to replicate how obt is used when executed inside a terminal. + process.chdir(path.join(__dirname, '/fixtures/readme-valid-uppercase')); + }); + + afterEach(function () { + // Change the current working directory back to the directory where you started running these tests from. + process.chdir(process.cwd()); + }); + + it('should not error', function () { + return obtBinPath() + .then(obt => { + return execa(obt, ['verify']); + }); + }); + }); }); describe('js', function () {