Skip to content

Commit

Permalink
improve path assertion and use it correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nmigueles committed Dec 2, 2024
1 parent e2fc0b6 commit 135149e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
15 changes: 8 additions & 7 deletions test/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ElementDefinition } from 'cytoscape'
import { existsSync } from 'fs'
import { existsSync, lstatSync, readdirSync } from 'fs'

Check warning on line 2 in test/assertions.ts

View workflow job for this annotation

GitHub Actions / test

'lstatSync' is defined but never used

Check warning on line 2 in test/assertions.ts

View workflow job for this annotation

GitHub Actions / test

'readdirSync' is defined but never used

type ElementDefinitionQuery = Partial<ElementDefinition['data']>

declare global {
export namespace Chai {
interface Assertion { // TODO: split into the separate modules
connect: (label: string, sourceLabel: string, targetLabel: string, width?: number, style?: string) => Assertion
pathExists(path: string): Assertion
pathExists(): Assertion
}

interface Include {
Expand All @@ -19,13 +19,14 @@ declare global {
export const pathAssertions: Chai.ChaiPlugin = (chai) => {
const { Assertion } = chai

Assertion.addMethod('pathExists', function (path) {
const exists = existsSync(path)
Assertion.addMethod('pathExists', function () {
new Assertion(this._obj).to.be.an('string').length.above(0)
const exists = existsSync(this._obj)
this.assert(
exists,
'expected path #{this} to exist',
'expected path #{this} to not exist',
path
`expected path ${this._obj} to exist`,
`expected path ${this._obj} not to exist`,
this._obj
)
})
}
Expand Down
77 changes: 38 additions & 39 deletions test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ describe('testing init', () => {
it('should create files successfully for default values: ci, no game, example name & git', async () => {
init(undefined, baseOptions)

expect(join(project, 'example.wlk')).to.pathExists
expect(join(project, 'testExample.wtest')).to.pathExists
expect(join(project, 'package.json')).to.pathExists
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists
expect(join(project, 'README.md')).to.pathExists
expect(join(project, '.gitignore')).to.pathExists
expect(join(project, 'mainExample.wpgm')).to.pathExists
expect(join(project, '.git')).to.pathExists
expect(join(project, '.git/HEAD')).to.pathExists
expect(join(project, 'example.wlk')).to.pathExists()
expect(join(project, 'testExample.wtest')).to.pathExists()
expect(join(project, 'package.json')).to.pathExists()
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists()
expect(join(project, 'README.md')).to.pathExists()
expect(join(project, '.gitignore')).to.pathExists()
expect(join(project, 'mainExample.wpgm')).not.to.pathExists()
expect(join(project, '.git')).to.pathExists()
expect(join(project, '.git/HEAD')).to.pathExists()
expect(getResourceFolder()).to.be.undefined

await test(undefined, {
Expand All @@ -69,13 +69,13 @@ describe('testing init', () => {
name: 'pepita',
})

expect(join(project, 'pepita.wlk')).to.pathExists
expect(join(project, 'testPepita.wtest')).to.pathExists
expect(join(project, 'mainPepita.wpgm')).to.pathExists
expect(join(project, 'package.json')).to.pathExists
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists
expect(join(project, 'README.md')).to.pathExists
expect(join(project, '.gitignore')).to.pathExists
expect(join(project, 'pepita.wlk')).to.pathExists()
expect(join(project, 'testPepita.wtest')).to.pathExists()
expect(join(project, 'mainPepita.wpgm')).to.pathExists()
expect(join(project, 'package.json')).to.pathExists()
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists()
expect(join(project, 'README.md')).to.pathExists()
expect(join(project, '.gitignore')).to.pathExists()
expect(getResourceFolder()).to.be.equal('assets')
})

Expand All @@ -84,42 +84,41 @@ describe('testing init', () => {
...baseOptions,
noCI: true,
noTest: true,
game: true,
name: 'pepita',
})

expect(join(project, 'pepita.wlk')).to.pathExists
expect(join(project, 'testPepita.wtest')).to.pathExists
expect(join(project, 'package.json')).to.pathExists
expect(join(project, 'mainPepita.wpgm')).to.pathExists
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists
expect(join(project, '.gitignore')).to.pathExists
expect(join(project, 'README.md')).to.pathExists
expect(join(project, 'pepita.wlk')).to.pathExists()
expect(join(project, 'testPepita.wtest')).not.to.pathExists()
expect(join(project, 'package.json')).to.pathExists()
expect(join(project, 'mainPepita.wpgm')).to.pathExists()
expect(join(project, GITHUB_FOLDER, 'ci.yml')).not.pathExists()
expect(join(project, '.gitignore')).to.pathExists()
expect(join(project, 'README.md')).to.pathExists()
})

it('should create files successfully with an argument for the folder name working in combination with project option', async () => {
init(customFolderName, baseOptions)

expect(join(customFolderProject, 'pepita.wlk')).to.pathExists
expect(join(customFolderProject, 'testPepita.wtest')).to.pathExists
expect(join(customFolderProject, 'mainPepita.wpgm')).to.pathExists
expect(join(customFolderProject, 'package.json')).to.pathExists
expect(join(customFolderProject, GITHUB_FOLDER, 'ci.yml')).to.pathExists
expect(join(customFolderProject, 'README.md')).to.pathExists
expect(join(customFolderProject, '.gitignore')).to.pathExists
expect(join(customFolderProject, 'example.wlk')).to.pathExists()
expect(join(customFolderProject, 'testExample.wtest')).to.pathExists()
expect(join(customFolderProject, 'package.json')).to.pathExists()
expect(join(customFolderProject, GITHUB_FOLDER, 'ci.yml')).to.pathExists()
expect(join(customFolderProject, 'README.md')).to.pathExists()
expect(join(customFolderProject, '.gitignore')).to.pathExists()
})

it('should skip the initialization of a git repository if notGit flag es enabled', async () => {
init(undefined, { ...baseOptions, noGit: true })

expect(join(project, '.git')).not.to.pathExists
expect(join(project, '.git/HEAD')).not.to.pathExists
expect(join(project, 'example.wlk')).to.pathExists
expect(join(project, 'testExample.wtest')).to.pathExists
expect(join(project, 'package.json')).to.pathExists
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists
expect(join(project, 'README.md')).to.pathExists
expect(join(project, '.gitignore')).to.pathExists
expect(join(project, 'mainExample.wpgm')).to.pathExists
expect(join(project, '.git')).not.to.pathExists()
expect(join(project, '.git/HEAD')).not.to.pathExists()
expect(join(project, 'example.wlk')).to.pathExists()
expect(join(project, 'testExample.wtest')).to.pathExists()
expect(join(project, 'package.json')).to.pathExists()
expect(join(project, GITHUB_FOLDER, 'ci.yml')).to.pathExists()
expect(join(project, 'README.md')).to.pathExists()
expect(join(project, '.gitignore')).to.pathExists()
expect(getResourceFolder()).to.be.undefined
})

Expand Down

0 comments on commit 135149e

Please sign in to comment.