Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
allow lowercased filename for readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Aug 13, 2020
1 parent 43acc93 commit 2e7888e
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/tasks/verify-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "test-component",
"main": [],
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 10 ** 2;
self.world = a;
12 changes: 12 additions & 0 deletions test/integration/verify/fixtures/readme-valid-lowercase/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@mixin oTestComponent() {
.o-test {
font-size: 18px;

&--error {
background-color: red;
color: white;
}
}
}

@include oTestComponent;
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"slack": "financialtimes/#origami-support"
},
"supportStatus": "experimental",
"browserFeatures": {},
"demosDefaults": {


"documentClasses": "",
"dependencies": []
},
"demos": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test-component

test component

## Licence

MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test-component

test component

## Licence

MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "test-component",
"main": [],
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 10 ** 2;
self.world = a;
12 changes: 12 additions & 0 deletions test/integration/verify/fixtures/readme-valid-uppercase/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@mixin oTestComponent() {
.o-test {
font-size: 18px;

&--error {
background-color: red;
color: white;
}
}
}

@include oTestComponent;
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"slack": "financialtimes/#origami-support"
},
"supportStatus": "experimental",
"browserFeatures": {},
"demosDefaults": {


"documentClasses": "",
"dependencies": []
},
"demos": []
}
82 changes: 82 additions & 0 deletions test/integration/verify/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {

Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand Down

0 comments on commit 2e7888e

Please sign in to comment.