diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 82f732f67..000000000 --- a/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -root = true - -# Unix-style newlines with a newline ending every file -[*] -end_of_line = lf -insert_final_newline = true - -[*{js,jsx}] -charset = utf-8 -indent_style = space -indent_size = 2 -trim_trailing_whitespace = true diff --git a/.eslintignore b/.eslintignore index 4ebc8aea5..404abb221 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -coverage +coverage/ diff --git a/.npmignore b/.npmignore index ae9d43cf1..dd60d50e8 100644 --- a/.npmignore +++ b/.npmignore @@ -1,9 +1,5 @@ -.DS_Store -.editorconfig -.eslintignore -.eslintrc +__tests__/ .github/ -.prettierignore -.prettierrc coverage/ -test/ +.eslint* +.prettier* diff --git a/.prettierignore b/.prettierignore index 4ebc8aea5..404abb221 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1 @@ -coverage +coverage/ diff --git a/LICENSE b/LICENSE index 75ca81c15..3bc78af7a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright © 2018 ReadMe.io +Copyright © 2021 ReadMe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in diff --git a/test/.eslintrc b/__tests__/.eslintrc similarity index 100% rename from test/.eslintrc rename to __tests__/.eslintrc diff --git a/test/fixtures/existing-docs/not-a-markdown-file b/__tests__/__fixtures__/existing-docs/not-a-markdown-file similarity index 100% rename from test/fixtures/existing-docs/not-a-markdown-file rename to __tests__/__fixtures__/existing-docs/not-a-markdown-file diff --git a/test/fixtures/existing-docs/simple-doc.md b/__tests__/__fixtures__/existing-docs/simple-doc.md similarity index 100% rename from test/fixtures/existing-docs/simple-doc.md rename to __tests__/__fixtures__/existing-docs/simple-doc.md diff --git a/test/fixtures/invalid-swagger.json b/__tests__/__fixtures__/invalid-swagger.json similarity index 100% rename from test/fixtures/invalid-swagger.json rename to __tests__/__fixtures__/invalid-swagger.json diff --git a/test/fixtures/new-docs/new-doc.md b/__tests__/__fixtures__/new-docs/new-doc.md similarity index 100% rename from test/fixtures/new-docs/new-doc.md rename to __tests__/__fixtures__/new-docs/new-doc.md diff --git a/test/fixtures/swagger.json b/__tests__/__fixtures__/swagger.json similarity index 100% rename from test/fixtures/swagger.json rename to __tests__/__fixtures__/swagger.json diff --git a/test/cmds/docs.test.js b/__tests__/cmds/docs.test.js similarity index 94% rename from test/cmds/docs.test.js rename to __tests__/cmds/docs.test.js index 758864694..017fcc8cc 100644 --- a/test/cmds/docs.test.js +++ b/__tests__/cmds/docs.test.js @@ -5,10 +5,10 @@ const path = require('path'); const crypto = require('crypto'); const frontMatter = require('gray-matter'); -const docs = require('../../cmds/docs/index'); -const docsEdit = require('../../cmds/docs/edit'); +const docs = require('../../src/cmds/docs'); +const docsEdit = require('../../src/cmds/docs/edit'); -const fixturesDir = `${__dirname}./../fixtures`; +const fixturesDir = `${__dirname}./../__fixtures__`; const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs'; const version = '1.0.0'; @@ -71,7 +71,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200); - return docs.run({ folder: './test/fixtures/existing-docs', key, version }).then(() => { + return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(() => { getMock.done(); putMock.done(); }); @@ -94,7 +94,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category: '5ae9ece93a685f47efb9a97c', slug, lastUpdatedHash: hash }); - return docs.run({ folder: './test/fixtures/existing-docs', key, version }).then(([message]) => { + return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(([message]) => { expect(message).toBe('`simple-doc` not updated. No changes.'); getMock.done(); }); @@ -133,7 +133,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(201); - return docs.run({ folder: './test/fixtures/new-docs', key, version }).then(() => { + return docs.run({ folder: './__tests__/__fixtures__/new-docs', key, version }).then(() => { getMock.done(); postMock.done(); }); diff --git a/test/cmds/login.test.js b/__tests__/cmds/login.test.js similarity index 96% rename from test/cmds/login.test.js rename to __tests__/cmds/login.test.js index cc4b0bc9f..c7e44cd19 100644 --- a/test/cmds/login.test.js +++ b/__tests__/cmds/login.test.js @@ -1,7 +1,7 @@ const nock = require('nock'); const config = require('config'); -const configStore = require('../../lib/configstore'); -const cmd = require('../../cmds/login'); +const configStore = require('../../src/lib/configstore'); +const cmd = require('../../src/cmds/login'); describe('rdme login', () => { beforeAll(() => nock.disableNetConnect()); diff --git a/test/cmds/logout.test.js b/__tests__/cmds/logout.test.js similarity index 82% rename from test/cmds/logout.test.js rename to __tests__/cmds/logout.test.js index 6960df8d7..0c7b46325 100644 --- a/test/cmds/logout.test.js +++ b/__tests__/cmds/logout.test.js @@ -1,7 +1,7 @@ const config = require('config'); -const configStore = require('../../lib/configstore'); -const cmd = require('../../cmds/logout'); -const loginCmd = require('../../cmds/login'); +const configStore = require('../../src/lib/configstore'); +const cmd = require('../../src/cmds/logout'); +const loginCmd = require('../../src/cmds/login'); describe('rdme logout', () => { it("should report the user as logged out if they aren't logged in", () => { diff --git a/test/cmds/open.test.js b/__tests__/cmds/open.test.js similarity index 82% rename from test/cmds/open.test.js rename to __tests__/cmds/open.test.js index d84835b9b..5a3d2e07e 100644 --- a/test/cmds/open.test.js +++ b/__tests__/cmds/open.test.js @@ -1,7 +1,7 @@ const config = require('config'); -const configStore = require('../../lib/configstore'); -const cmd = require('../../cmds/open'); -const loginCmd = require('../../cmds/login'); +const configStore = require('../../src/lib/configstore'); +const cmd = require('../../src/cmds/open'); +const loginCmd = require('../../src/cmds/login'); describe('rdme open', () => { it('should error if no project provided', () => { diff --git a/test/cmds/swagger.test.js b/__tests__/cmds/swagger.test.js similarity index 88% rename from test/cmds/swagger.test.js rename to __tests__/cmds/swagger.test.js index 03405be29..8c76adf87 100644 --- a/test/cmds/swagger.test.js +++ b/__tests__/cmds/swagger.test.js @@ -1,13 +1,13 @@ const nock = require('nock'); const config = require('config'); const fs = require('fs'); -const promptHandler = require('../../lib/prompts'); -const swagger = require('../../cmds/swagger'); +const promptHandler = require('../../src/lib/prompts'); +const swagger = require('../../src/cmds/swagger'); const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs'; const version = '1.0.0'; -jest.mock('../../lib/prompts'); +jest.mock('../../src/lib/prompts'); const getCommandOutput = () => { return [console.warn.mock.calls.join('\n\n'), console.log.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); @@ -51,7 +51,7 @@ describe('rdme swagger', () => { // Surface our test fixture to the root directory so rdme can autodiscover it. It's easier to do // this than mocking out the fs module because mocking the fs module here causes Jest sourcemaps // to break. - fs.copyFileSync('./test/fixtures/swagger.json', './swagger.json'); + fs.copyFileSync('./__tests__/__fixtures__/swagger.json', './swagger.json'); return swagger.run({ key }).then(() => { expect(console.log).toHaveBeenCalledTimes(2); @@ -86,7 +86,7 @@ describe('rdme swagger', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - return expect(swagger.run({ spec: './test/fixtures/swagger.json', key, version })) + return expect(swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key, version })) .rejects.toThrow('The version you specified') .then(() => mock.done()); }); @@ -103,7 +103,7 @@ describe('rdme swagger', () => { .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); - return swagger.run({ spec: './test/fixtures/swagger.json', key, version }).then(() => { + return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }).then(() => { expect(console.log).toHaveBeenCalledTimes(1); const output = getCommandOutput(); @@ -134,7 +134,7 @@ describe('rdme swagger', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - return expect(swagger.run({ spec: './test/fixtures/invalid-swagger.json', key, version })) + return expect(swagger.run({ spec: './__tests__/__fixtures__/invalid-swagger.json', key, version })) .rejects.toThrow('README VALIDATION ERROR "x-samples-languages" must be of type "Array"') .then(() => mock.done()); }); @@ -161,7 +161,7 @@ describe('rdme swagger', () => { .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); - return swagger.run({ spec: './test/fixtures/swagger.json', key }).then(() => { + return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key }).then(() => { mock.done(); }); }); @@ -174,7 +174,7 @@ describe('rdme swagger', () => { .basicAuth({ user: key }) .reply(201, { body: '{ id: 1 }' }); - return swagger.run({ spec: './test/fixtures/swagger.json', key, id, version }).then(() => { + return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', key, id, version }).then(() => { mock.done(); }); }); @@ -187,7 +187,7 @@ describe('rdme swagger', () => { .basicAuth({ user: key }) .reply(201, { id: 1 }, { location: exampleRefLocation }); - return swagger.run({ spec: './test/fixtures/swagger.json', token: `${key}-${id}`, version }).then(() => { + return swagger.run({ spec: './__tests__/__fixtures__/swagger.json', token: `${key}-${id}`, version }).then(() => { expect(console.warn).toHaveBeenCalledTimes(1); expect(console.log).toHaveBeenCalledTimes(1); @@ -200,7 +200,7 @@ describe('rdme swagger', () => { }); it('should error if no api key provided', async () => { - await expect(swagger.run({ spec: './test/fixtures/swagger.json' })).rejects.toThrow( + await expect(swagger.run({ spec: './__tests__/__fixtures__/swagger.json' })).rejects.toThrow( 'No project API key provided. Please use `--key`.' ); }); diff --git a/test/cmds/versions.test.js b/__tests__/cmds/versions.test.js similarity index 96% rename from test/cmds/versions.test.js rename to __tests__/cmds/versions.test.js index b8a2894e0..426b99330 100644 --- a/test/cmds/versions.test.js +++ b/__tests__/cmds/versions.test.js @@ -1,11 +1,11 @@ const nock = require('nock'); const config = require('config'); -const promptHandler = require('../../lib/prompts'); +const promptHandler = require('../../src/lib/prompts'); -const versions = require('../../cmds/versions/index'); -const createVersion = require('../../cmds/versions/create'); -const deleteVersion = require('../../cmds/versions/delete'); -const updateVersion = require('../../cmds/versions/update'); +const versions = require('../../src/cmds/versions'); +const createVersion = require('../../src/cmds/versions/create'); +const deleteVersion = require('../../src/cmds/versions/delete'); +const updateVersion = require('../../src/cmds/versions/update'); const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs'; const version = '1.0.0'; @@ -31,7 +31,7 @@ const version2Payload = { version: version2, }; -jest.mock('../../lib/prompts'); +jest.mock('../../src/lib/prompts'); describe('rdme versions*', () => { beforeAll(() => nock.disableNetConnect()); diff --git a/test/cmds/whoami.test.js b/__tests__/cmds/whoami.test.js similarity index 83% rename from test/cmds/whoami.test.js rename to __tests__/cmds/whoami.test.js index 701e9044f..336a64a67 100644 --- a/test/cmds/whoami.test.js +++ b/__tests__/cmds/whoami.test.js @@ -1,7 +1,7 @@ const config = require('config'); -const configStore = require('../../lib/configstore'); -const cmd = require('../../cmds/whoami'); -const loginCmd = require('../../cmds/login'); +const configStore = require('../../src/lib/configstore'); +const cmd = require('../../src/cmds/whoami'); +const loginCmd = require('../../src/cmds/login'); describe('rdme whoami', () => { it('should error if user is not authenticated', () => { diff --git a/test/cli.test.js b/__tests__/index.test.js similarity index 97% rename from test/cli.test.js rename to __tests__/index.test.js index bad2d2208..d5f992fce 100644 --- a/test/cli.test.js +++ b/__tests__/index.test.js @@ -1,10 +1,10 @@ require('colors'); const nock = require('nock'); -const cli = require('../cli'); +const cli = require('../src'); const { version } = require('../package.json'); -const conf = require('../lib/configstore'); -const swaggerCmd = require('../cmds/swagger'); +const conf = require('../src/lib/configstore'); +const swaggerCmd = require('../src/cmds/swagger'); describe('cli', () => { it('command not found', () => { diff --git a/test/lib/apiError.test.js b/__tests__/lib/apiError.test.js similarity index 96% rename from test/lib/apiError.test.js rename to __tests__/lib/apiError.test.js index 5b83125a3..dad14d642 100644 --- a/test/lib/apiError.test.js +++ b/__tests__/lib/apiError.test.js @@ -1,4 +1,4 @@ -const APIError = require('../../lib/apiError'); +const APIError = require('../../src/lib/apiError'); const response = { error: 'VERSION_FORK_EMPTY', diff --git a/test/lib/commands.test.js b/__tests__/lib/commands.test.js similarity index 90% rename from test/lib/commands.test.js rename to __tests__/lib/commands.test.js index b58c0658b..660ed2e68 100644 --- a/test/lib/commands.test.js +++ b/__tests__/lib/commands.test.js @@ -1,14 +1,14 @@ -const commands = require('../../lib/commands').list(); +const commands = require('../../src/lib/commands'); describe('utils', () => { - describe('#getCommands', () => { + describe('#list', () => { it('should have commands returned', () => { - expect(commands).not.toHaveLength(0); + expect(commands.list()).not.toHaveLength(0); }); describe('commands', () => { it('should be configured properly', () => { - commands.forEach(c => { + commands.list().forEach(c => { const cmd = c.command; expect(typeof cmd.command === 'string' && cmd.command.length !== 0).toBe(true); @@ -31,7 +31,7 @@ describe('utils', () => { }); it('should abide by our cli standards', () => { - commands.forEach(c => { + commands.list().forEach(c => { const cmd = c.command; expect(cmd.description[cmd.description.length - 1]).toBe('.'); diff --git a/test/lib/prompts.test.js b/__tests__/lib/prompts.test.js similarity index 98% rename from test/lib/prompts.test.js rename to __tests__/lib/prompts.test.js index 207061f1e..e11bdbb03 100644 --- a/test/lib/prompts.test.js +++ b/__tests__/lib/prompts.test.js @@ -1,5 +1,5 @@ const Enquirer = require('enquirer'); -const promptHandler = require('../../lib/prompts'); +const promptHandler = require('../../src/lib/prompts'); const versionlist = [ { diff --git a/test/set-node-env.js b/__tests__/set-node-env.js similarity index 100% rename from test/set-node-env.js rename to __tests__/set-node-env.js diff --git a/rdme.js b/bin/rdme similarity index 92% rename from rdme.js rename to bin/rdme index 4738bd4e4..f1e01d2a7 100755 --- a/rdme.js +++ b/bin/rdme @@ -1,7 +1,7 @@ #! /usr/bin/env node require('colors'); -require('./cli')(process.argv.slice(2)) +require('../src')(process.argv.slice(2)) .then(msg => { if (msg) console.log(msg); process.exit(0); diff --git a/package.json b/package.json index 2d3e3e39c..35daeb157 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "node": "^12 || ^14 || ^16" }, "bin": { - "rdme": "rdme.js" + "rdme": "bin/rdme" }, "tags": [ "api", @@ -63,9 +63,6 @@ "test": "jest --coverage" }, "jest": { - "setupFiles": [ - "./test/set-node-env" - ], "coverageThreshold": { "global": { "branches": 80, @@ -73,7 +70,13 @@ "lines": 90, "statements": 90 } - } + }, + "setupFiles": [ + "./__tests__/set-node-env" + ], + "testPathIgnorePatterns": [ + "./__tests__/set-node-env" + ] }, "prettier": "@readme/eslint-config/prettier" } diff --git a/cmds/docs/edit.js b/src/cmds/docs/edit.js similarity index 100% rename from cmds/docs/edit.js rename to src/cmds/docs/edit.js diff --git a/cmds/docs/index.js b/src/cmds/docs/index.js similarity index 100% rename from cmds/docs/index.js rename to src/cmds/docs/index.js diff --git a/cmds/login.js b/src/cmds/login.js similarity index 100% rename from cmds/login.js rename to src/cmds/login.js diff --git a/cmds/logout.js b/src/cmds/logout.js similarity index 100% rename from cmds/logout.js rename to src/cmds/logout.js diff --git a/cmds/oas.js b/src/cmds/oas.js similarity index 82% rename from cmds/oas.js rename to src/cmds/oas.js index 3aa3d7ec7..67d07bd8b 100644 --- a/cmds/oas.js +++ b/src/cmds/oas.js @@ -10,7 +10,7 @@ exports.position = 1; exports.args = []; exports.run = function () { - const cp = spawn(path.join(__dirname, '..', 'node_modules', '.bin', 'oas'), process.argv.slice(3), { + const cp = spawn(path.join(__dirname, '..', '..', 'node_modules', '.bin', 'oas'), process.argv.slice(3), { stdio: 'inherit', }); diff --git a/cmds/open.js b/src/cmds/open.js similarity index 100% rename from cmds/open.js rename to src/cmds/open.js diff --git a/cmds/swagger.js b/src/cmds/swagger.js similarity index 100% rename from cmds/swagger.js rename to src/cmds/swagger.js diff --git a/cmds/versions/create.js b/src/cmds/versions/create.js similarity index 100% rename from cmds/versions/create.js rename to src/cmds/versions/create.js diff --git a/cmds/versions/delete.js b/src/cmds/versions/delete.js similarity index 100% rename from cmds/versions/delete.js rename to src/cmds/versions/delete.js diff --git a/cmds/versions/index.js b/src/cmds/versions/index.js similarity index 100% rename from cmds/versions/index.js rename to src/cmds/versions/index.js diff --git a/cmds/versions/update.js b/src/cmds/versions/update.js similarity index 100% rename from cmds/versions/update.js rename to src/cmds/versions/update.js diff --git a/cmds/whoami.js b/src/cmds/whoami.js similarity index 100% rename from cmds/whoami.js rename to src/cmds/whoami.js diff --git a/cli.js b/src/index.js similarity index 97% rename from cli.js rename to src/index.js index 258f10984..12a1150c2 100644 --- a/cli.js +++ b/src/index.js @@ -9,13 +9,13 @@ const path = require('path'); // but since this is only supposed to be a cli and not // requireable, i think this is okay const configDir = process.env.NODE_CONFIG_DIR; -process.env.NODE_CONFIG_DIR = path.join(__dirname, '/config'); +process.env.NODE_CONFIG_DIR = path.join(__dirname, '../config'); const config = require('config'); process.env.NODE_CONFIG_DIR = configDir; -const { version } = require('./package.json'); +const { version } = require('../package.json'); const configStore = require('./lib/configstore'); const help = require('./lib/help'); const commands = require('./lib/commands'); diff --git a/lib/apiError.js b/src/lib/apiError.js similarity index 100% rename from lib/apiError.js rename to src/lib/apiError.js diff --git a/lib/commands.js b/src/lib/commands.js similarity index 100% rename from lib/commands.js rename to src/lib/commands.js diff --git a/lib/configstore.js b/src/lib/configstore.js similarity index 75% rename from lib/configstore.js rename to src/lib/configstore.js index e8a0aed69..645fc4160 100644 --- a/lib/configstore.js +++ b/src/lib/configstore.js @@ -1,4 +1,4 @@ const Configstore = require('configstore'); -const pkg = require('../package.json'); +const pkg = require('../../package.json'); module.exports = new Configstore(`${pkg.name}-${process.env.NODE_ENV || 'production'}`); diff --git a/lib/help.js b/src/lib/help.js similarity index 100% rename from lib/help.js rename to src/lib/help.js diff --git a/lib/prompts.js b/src/lib/prompts.js similarity index 100% rename from lib/prompts.js rename to src/lib/prompts.js