Skip to content

Commit

Permalink
Merge pull request #34 from davidecaruso/increase-coverage
Browse files Browse the repository at this point in the history
Increase code coverage
  • Loading branch information
davidecaruso authored Sep 4, 2022
2 parents 2c6caa7 + 956b88e commit d4c5e19
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shell.js",
"version": "4.3.0",
"version": "4.3.1",
"description": "A JavaScript library to create HTML terminals in web pages.",
"author": "Davide Caruso <[email protected]>",
"homepage": "https://shelljs.io",
Expand Down
18 changes: 18 additions & 0 deletions src/Classes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ describe('Classes', () => {
expect(
buildClasses({ engine: 'ubuntu', theme: 'light', shadow: false, responsive: true })('')
).to.be.deep.equal('shell shell--ubuntu shell--light shell--responsive')
expect(
buildClasses({
typing: { ctor: Object },
engine: 'ubuntu',
theme: 'light',
shadow: false,
responsive: true,
})('')
).to.be.deep.equal('shell shell--ubuntu shell--light shell--responsive shell--typed')
})
})
describe('with current classes', () => {
Expand All @@ -66,6 +75,15 @@ describe('Classes', () => {
expect(
buildClasses({ engine: 'ubuntu', theme: 'light', shadow: false, responsive: true })('foo bar baz')
).to.be.deep.equal('foo bar baz shell shell--ubuntu shell--light shell--responsive')
expect(
buildClasses({
typing: { ctor: Object },
engine: 'ubuntu',
theme: 'light',
shadow: false,
responsive: true,
})('foo bar baz')
).to.be.deep.equal('foo bar baz shell shell--ubuntu shell--light shell--responsive shell--typed')
})
})
})
Expand Down
6 changes: 6 additions & 0 deletions src/Command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ describe('Command', () => {
)
})
})
describe('with root user', () => {
const config: Config = { ...defaultConfig, root: true }
it('should not print anything', () => {
expect(exec(input(config)('sudo -i'))).to.be.deep.equal(undefined)
})
})
})

describe('exit', () => {
Expand Down
23 changes: 23 additions & 0 deletions src/Config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai'
import {
buildConfig,
defaultConfig,
hasShadow,
isDefault,
Expand Down Expand Up @@ -92,4 +93,26 @@ describe('Config', () => {
expect(hasShadow({ shadow: true })).to.be.true
})
})

describe('buildConfig', () => {
it('should return built config', () => {
expect(buildConfig({})).to.be.deep.equal(defaultConfig)
expect(buildConfig({ engine: 'macos' })).to.be.deep.equal({ ...defaultConfig, engine: 'macos', path: '~' })
expect(buildConfig({ engine: 'ubuntu' })).to.be.deep.equal({
...defaultConfig,
engine: 'ubuntu',
path: '~',
})
expect(buildConfig({ engine: 'default' })).to.be.deep.equal({
...defaultConfig,
engine: 'default',
path: '~',
})
expect(buildConfig({ engine: 'windows' })).to.be.deep.equal({
...defaultConfig,
engine: 'windows',
path: 'C:\\Windows\\system32\\',
})
})
})
})
4 changes: 4 additions & 0 deletions src/Content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ describe('Content', () => {
describe('with "ubuntu" engine', () => {
it('should return empty string', () => {
expect(login({ ...defaultConfig, engine: 'ubuntu' })(date)).to.be.deep.equal('')
expect(login({ ...defaultConfig, engine: 'ubuntu' })()).to.be.deep.equal('')
})
})
describe('with "windows" engine', () => {
it('should return empty string', () => {
expect(login({ ...defaultConfig, engine: 'windows' })(date)).to.be.deep.equal('')
expect(login({ ...defaultConfig, engine: 'windows' })()).to.be.deep.equal('')
})
})
describe('with "default" engine', () => {
it('should return empty string', () => {
expect(login({ ...defaultConfig, engine: 'default' })(date)).to.be.deep.equal('')
expect(login({ ...defaultConfig, engine: 'default' })()).to.be.deep.equal('')
})
})
describe('with "macos" engine', () => {
it('should return login string', () => {
expect(login({ ...defaultConfig, engine: 'macos' })(date)).to.be.not.equal('')
expect(login({ ...defaultConfig, engine: 'macos' })()).to.be.not.equal('')
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/Content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Config, isMacOs, isRoot, isWindows } from './Config'
const prefix = ({ context }: Pick<IO, 'context'>): string =>
`<span class="${linePrefixClass}">` +
(isWindows(context)
? `<span class="path">${context.path}</span>` + `<span class="char">${isRoot(context) ? '#' : '&gt;'}</span>`
? `<span class="path">${context.path}</span><span class="char">&gt;</span>`
: `<span class="user">${isRoot(context) ? 'root' : context.user}@</span>` +
`<span class="host">${context.host}</span>` +
`<span class="colon">:</span>` +
Expand Down

0 comments on commit d4c5e19

Please sign in to comment.