Skip to content

Commit

Permalink
Merge pull request #12 from drashland/issue-#5-improve-tests
Browse files Browse the repository at this point in the history
Issue #5 improve tests
  • Loading branch information
Guergeiro authored Jun 9, 2020
2 parents b7c402d + fe94668 commit 7649d93
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 40 deletions.
8 changes: 6 additions & 2 deletions dmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const helpMessage: string = "\n" +
"\n" +
" info" +
"\n" +
" Shows information about the given module." +
" Shows information about the given module, be it std or 3rd party. The 3rd party module must be referenced at https://deno.land/x/" +
"\n" +
"\n" +
"EXAMPLE USAGE:" +
Expand Down Expand Up @@ -297,7 +297,11 @@ export const purposes: { [key: string]: Function } = {
denoLandUrl = "https://deno.land/x/" + name + "@" + latestVersion
}
const importLine = "import * as " + name + " from \"" + denoLandUrl + "\";"
console.info(colours.yellow(`\nInformation on ${name}\n\n - Name: ${name}\n - Description: ${description}\n - deno.land Link: ${denoLandUrl}\n - GitHub Repository: ${gitHubUrl}\n - Import Statement: ${importLine}\n - Latest Version: ${latestVersion}\n`))
console.info(
'\n' +
`Information on ${name}\n\n - Name: ${name}\n - Description: ${description}\n - deno.land Link: ${denoLandUrl}\n - GitHub Repository: ${gitHubUrl}\n - Import Statement: ${importLine}\n - Latest Version: ${latestVersion}` +
'\n'
)
Deno.exit()
}
}
176 changes: 162 additions & 14 deletions tests/check_test.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1,266 @@
import { assertEquals } from "../deps.ts"
import { assertEquals, colours } from "../deps.ts"

// Check a specific dep that can be updated
Deno.test({
name: 'Check | Single | Modules to Update Exist',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "fs"],
cwd: "./tests/out-of-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
const error = await p.stderr
p.close()
assertEquals(status.code, 0)
assertEquals(status.success, true)
assertEquals(error, undefined)
const output = await p.output()
await p.close()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n' +
'Comparing versions...\n' +
colours.yellow('fs can be updated from 0.53.0 to 0.56.0') + '\n' +
'To update, run: \n' +
' dmm update fs' +
'\n'
)
assertEquals(stderr, '')
}
})

// Check a specific dep that is already up to date
Deno.test({
name: 'Check | Single | No Modules to Update',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "fs"],
cwd: "./tests/up-to-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
const error = await p.stderr
p.close()
assertEquals(status.code, 0)
assertEquals(status.success, true)
assertEquals(error, undefined)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n' +
'Comparing versions...\n' +
colours.green('Your dependencies are up to date') + '\n'
)
assertEquals(stderr, '')
}
})


// Check a list of deps that can be updated
Deno.test({
name: 'Check | Many | Modules to Update Exist',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "fs", "drash"],
cwd: "./tests/out-of-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
const error = await p.stderr
p.close()
assertEquals(status.code, 0)
assertEquals(status.success, true)
assertEquals(error, undefined)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n' +
'Comparing versions...\n' +
colours.yellow('drash can be updated from v1.0.0 to v1.0.5') + '\n' +
colours.yellow('fs can be updated from 0.53.0 to 0.56.0') + '\n' +
'To update, run: \n' +
' dmm update drash fs' +
'\n'
)
assertEquals(stderr, '')
}
})

// Check a list of deps that are already up to date
Deno.test({
name: 'Check | Many | No Modules to Update',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "fs", "drash"],
cwd: "./tests/up-to-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
const error = await p.stderr
p.close()
assertEquals(status.code, 0)
assertEquals(status.success, true)
assertEquals(error, undefined)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n' +
'Comparing versions...\n' +
colours.green('Your dependencies are up to date') + '\n'
)
assertEquals(stderr, '')
}
})

// Check every dep and all of them are out of date
Deno.test({
name: 'Check | All | Modules to Update Exist',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check"],
cwd: "./tests/out-of-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
const error = await p.stderr
p.close()
assertEquals(status.code, 0)
assertEquals(status.success, true)
assertEquals(error, undefined)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n' +
'Comparing versions...\n' +
colours.yellow('drash can be updated from v1.0.0 to v1.0.5') + '\n' +
colours.yellow('fs can be updated from 0.53.0 to 0.56.0') + '\n' +
colours.yellow('fmt can be updated from v0.53.0 to v0.56.0') + '\n' +
'To update, run: \n' +
' dmm update drash fs fmt' +
'\n'
)
assertEquals(stderr, '')
}
})

// Check every dep and all of them are already up to date
Deno.test({
name: 'Check | All | No Modules to Update',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check"],
cwd: "./tests/up-to-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
const error = await p.stderr
p.close()
assertEquals(status.code, 0)
assertEquals(status.success, true)
assertEquals(error, undefined)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n' +
'Comparing versions...\n' +
colours.green('Your dependencies are up to date') + '\n'
)
assertEquals(stderr, '')
}
})

Deno.test({
name: 'Check | Modules Dont Exist in Dependencies',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "denon", "io"],
cwd: "./tests/up-to-date-deps",
stdout: "piped",
stderr: "piped",
})
const status = await p.status()
p.close()
assertEquals(status.code, 1)
assertEquals(status.success, false)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n'
)
assertEquals(stderr, colours.red('Modules specified do not exist in your dependencies.') + '\n')
}
})

Deno.test({
name: 'Check | std | Not Found',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "http"],
cwd: "./tests/up-to-date-deps",
stdout: "piped",
stderr: "piped"
})
const status = await p.status()
p.close()
assertEquals(status.code, 1)
assertEquals(status.success, false)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n'
)
assertEquals(stderr, colours.red('Modules specified do not exist in your dependencies.') + '\n')
}
})

Deno.test({
name: 'Check | 3rd Party | Not Found',
//ignore: true,
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "check", "io"],
cwd: "./tests/up-to-date-deps",
stdout: "piped",
stderr: "piped"
})
const status = await p.status()
p.close()
assertEquals(status.code, 1)
assertEquals(status.success, false)
const output = await p.output()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout,
'Gathering facts...\n' +
'Reading deps.ts to gather your dependencies...\n'
)
assertEquals(stderr, colours.red('Modules specified do not exist in your dependencies.') + '\n')
}
})
25 changes: 20 additions & 5 deletions tests/error_test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import {assertEquals} from "../deps.ts";
import { assertEquals, colours } from "../deps.ts";

Deno.test({
name: 'No Purpose',
async fn(): Promise<void> {
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts"],
cwd: "./tests/up-to-date-deps",
stdout: "null"
stdout: "piped",
stderr: "piped"
})
const status = await p.status()
p.close()
assertEquals(status.code, 1)
assertEquals(status.success, false)
const output = await p.output()
await p.close()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout, '')
assertEquals(stderr, colours.red('Invalid arguments. See --help') + '\n')
}

})

Deno.test({
Expand All @@ -21,11 +29,18 @@ Deno.test({
const p = await Deno.run({
cmd: ["deno", "run", "--allow-net", "--allow-read", "../../mod.ts", "something"],
cwd: "./tests/up-to-date-deps",
stdout: "null"
stdout: "piped",
stderr: "piped"
})
const status = await p.status()
p.close()
assertEquals(status.code, 1)
assertEquals(status.success, false)
const output = await p.output()
await p.close()
const stdout = new TextDecoder('utf-8').decode(output)
const error = await p.stderrOutput()
const stderr = new TextDecoder('utf-8').decode(error)
assertEquals(stdout, 'Gathering facts...\n')
assertEquals(stderr, colours.red('Specify either `check`, `info` or `update`. See --help') + '\n')
}
})
Loading

0 comments on commit 7649d93

Please sign in to comment.