Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Mar 21, 2024
1 parent 8bf9df4 commit 34864d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test-with-coverage": "npm run lint && nyc --reporter=json --lines 70 npm run test:unit",
"lint": "eslint . ",
"lint:fix": "eslint . --fix",
"test:unit": "mocha --parallel -r ts-node/register/transpile-only test/**/*.test.ts --timeout 7000",
"test:unit": "mocha -r ts-node/register/transpile-only test/**/*.test.ts --timeout 7000",
"build": "shx rm -rf build && shx mkdir ./build && shx cp -r ./public ./build/public && tsc -p ./tsconfig.build.json",
"watch": "npm run build -- -w",
"pack": "pkg ."
Expand Down
3 changes: 3 additions & 0 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl

export const getImages = (projectPath: string, assetsFolder: string): Image[] => {
const baseFolder = join(projectPath, assetsFolder)
if (!existsSync(baseFolder))
throw `Folder image ${baseFolder} does not exist`


const fileRelativeFor = (fileName: string) => ({ name: fileName, url: fileName })

Expand Down
16 changes: 10 additions & 6 deletions test/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ chai.should()
const expect = chai.expect

const project = join('examples', 'run-examples', 'basic-example')
const assets = 'assets'

describe('testing run', () => {

const buildOptions = (game: boolean, assets: string | undefined) => ({
const buildOptions = (game: boolean, assets: string) => ({
game,
project,
assets,
Expand All @@ -23,12 +24,12 @@ describe('testing run', () => {

describe('getAssetsPath', () => {

it('should return assets folder from options if it exists', () => {
expect(getAssetsFolder(buildOptions(true, 'myAssets'))).to.equal('myAssets')
it('should return assets folder from package if it exists', () => {
expect(getAssetsFolder(buildOptions(true, 'myAssets' /** Ignored :( */))).to.equal('specialAssets')
})

it('should return assets folder from package if options is not set', () => {
expect(getAssetsFolder(buildOptions(true, undefined))).to.equal('specialAssets')
it('should return assets folder from package with default option', () => {
expect(getAssetsFolder(buildOptions(true, assets))).to.equal('specialAssets')
})

it('should return undefined if game is not set', () => {
Expand Down Expand Up @@ -121,7 +122,7 @@ describe('testing run', () => {
})

it('should return all images even if assets folder is not present', () => {
expect(getImages(imageProject, undefined)).to.deep.equal(
expect(getImages(imageProject, '')).to.deep.equal(
[
{
'name': join('assets', 'medium', '3.png'),
Expand Down Expand Up @@ -168,6 +169,7 @@ describe('testing run', () => {
skipValidations: false,
game: false,
startDiagram: false,
assets,
})
expect(spyCalledWithSubstring(consoleLogSpy, 'Pepita empieza con 70')).to.be.true
expect(spyCalledWithSubstring(consoleLogSpy, 'Vuela')).to.be.true
Expand All @@ -187,6 +189,7 @@ describe('testing run', () => {
skipValidations: false,
game: false,
startDiagram: false,
assets,
})
expect(processExitSpy.calledWith(21)).to.be.true
expect(fileLoggerInfoSpy.calledOnce).to.be.true
Expand Down Expand Up @@ -216,6 +219,7 @@ describe('testing run', () => {
skipValidations: false,
game: true,
startDiagram: true,
assets,
})
await clock.runAllAsync()
})
Expand Down

0 comments on commit 34864d8

Please sign in to comment.