Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix de pathAssertion #205

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
PalumboN marked this conversation as resolved.
Show resolved Hide resolved

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 @@
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