This repository has been archived by the owner on Dec 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from form8ion/alpha
Initial version
- Loading branch information
Showing
13 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
extends: | ||
- '@form8ion' | ||
- '@form8ion/mocha' | ||
- '@form8ion/mocha' | ||
|
||
overrides: | ||
- files: example.js | ||
rules: | ||
import/no-extraneous-dependencies: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
// #### Import | ||
// remark-usage-ignore-next | ||
/* eslint-disable-next-line no-unused-vars */ | ||
import liftJavascript from './lib/index.cjs'; | ||
import stubbedFs from 'mock-fs'; | ||
import {lift, test} from './lib/index.cjs'; | ||
|
||
// remark-usage-ignore-next | ||
stubbedFs(); | ||
|
||
// #### Execute | ||
|
||
if (test({projectRoot: process.cwd()})) { | ||
lift({results: {dependencies: [], devDependencies: [], scripts: {}, elintConfigs: []}}); | ||
} | ||
// remark-usage-ignore-next | ||
stubbedFs.restore(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {default as lift} from './lift'; | ||
export {default as test} from './test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sinon from 'sinon'; | ||
import any from '@travi/any'; | ||
import {assert} from 'chai'; | ||
import * as scriptsLifter from './scripts'; | ||
import lift from './lift'; | ||
|
||
suite('lift', () => { | ||
let sandbox; | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(scriptsLifter, 'default'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that results specific to js projects are lifted', async () => { | ||
const projectRoot = any.string(); | ||
const scripts = any.simpleObject(); | ||
const results = {...any.simpleObject(), scripts}; | ||
|
||
await lift({projectRoot, results}); | ||
|
||
assert.calledWith(scriptsLifter.default, {projectRoot, scripts}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import liftScripts from './scripts'; | ||
|
||
export default async function ({results, projectRoot}) { | ||
await liftScripts({projectRoot, scripts: results.scripts}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {promises as fs} from 'fs'; | ||
import sinon from 'sinon'; | ||
import {assert} from 'chai'; | ||
import any from '@travi/any'; | ||
import liftScripts from './scripts'; | ||
|
||
suite('scripts lifter', () => { | ||
let sandbox; | ||
const projectRoot = any.string(); | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(fs, 'readFile'); | ||
sandbox.stub(fs, 'writeFile'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that the scripts are added to the `package.json`', async () => { | ||
const pathToPackageJson = `${projectRoot}/package.json`; | ||
const scripts = any.simpleObject(); | ||
const originalScripts = any.simpleObject(); | ||
const packageJsonContents = any.simpleObject(); | ||
fs.readFile | ||
.withArgs(pathToPackageJson, 'utf8') | ||
.resolves(JSON.stringify({...packageJsonContents, scripts: originalScripts})); | ||
|
||
await liftScripts({projectRoot, scripts}); | ||
|
||
assert.calledWith( | ||
fs.writeFile, | ||
pathToPackageJson, | ||
JSON.stringify({...packageJsonContents, scripts: {...originalScripts, ...scripts}}, null, 2) | ||
); | ||
}); | ||
|
||
test('that no updates are applied if no new scripts are provided', async () => { | ||
await liftScripts({}); | ||
|
||
assert.notCalled(fs.readFile); | ||
assert.notCalled(fs.writeFile); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {promises as fs} from 'fs'; | ||
|
||
export default async function ({projectRoot, scripts}) { | ||
if (scripts) { | ||
const pathToPackageJson = `${projectRoot}/package.json`; | ||
|
||
const existingPackageJsonContents = JSON.parse(await fs.readFile(pathToPackageJson, 'utf8')); | ||
|
||
await fs.writeFile( | ||
pathToPackageJson, | ||
JSON.stringify( | ||
{...existingPackageJsonContents, scripts: {...existingPackageJsonContents.scripts, ...scripts}}, | ||
null, | ||
2 | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {promises as fs} from 'fs'; | ||
import sinon from 'sinon'; | ||
import {assert} from 'chai'; | ||
import any from '@travi/any'; | ||
import testApplicability from './test'; | ||
|
||
suite('applicability test', () => { | ||
let sandbox; | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(fs, 'stat'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that `true` is returned if the project has an `.nvmrc` file', async () => { | ||
const projectRoot = any.string(); | ||
fs.stat.withArgs(`${projectRoot}/.nvmrc`).returns({isFile: () => true}); | ||
|
||
assert.isTrue(await testApplicability({projectRoot})); | ||
}); | ||
|
||
test('that `false` is returned if the project\'s `.nvmrc` is not file', async () => { | ||
const projectRoot = any.string(); | ||
fs.stat.withArgs(`${projectRoot}/.nvmrc`).returns({isFile: () => false}); | ||
|
||
assert.isFalse(await testApplicability({projectRoot})); | ||
}); | ||
|
||
test('that `false` is returned if the project does not have an `.nvmrc` file', async () => { | ||
const error = new Error(); | ||
error.code = 'ENOENT'; | ||
fs.stat.rejects(error); | ||
|
||
assert.isFalse(await testApplicability({})); | ||
}); | ||
|
||
test('that errors other than for missing file', async () => { | ||
const error = new Error(); | ||
error.code = any.word(); | ||
fs.stat.rejects(error); | ||
|
||
try { | ||
await testApplicability({}); | ||
|
||
throw new Error('an error should have been thrown by the module under test'); | ||
} catch (e) { | ||
assert.equal(e, error); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {promises as fs} from 'fs'; | ||
|
||
export default async function ({projectRoot}) { | ||
try { | ||
const stats = await fs.stat(`${projectRoot}/.nvmrc`); | ||
|
||
return stats.isFile(); | ||
} catch (e) { | ||
if ('ENOENT' === e.code) return false; | ||
|
||
throw e; | ||
} | ||
} |