This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
669317f
commit 36c57e9
Showing
14 changed files
with
440 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,143 @@ | ||
import { stdout } from 'stdout-stderr'; | ||
import { accessPromise, mkdirPromise, rimrafPromise, OutputStream } from '../common/io'; | ||
import * as nodePath from 'path'; | ||
import { stdout } from 'stdout-stderr'; | ||
|
||
import Play from '../commands/play'; | ||
import { | ||
accessPromise, | ||
mkdirPromise, | ||
OutputStream, | ||
rimrafPromise, | ||
} from '../common/io'; | ||
|
||
describe('Play CLI command', () => { | ||
const baseFixture = nodePath.join('fixtures', 'playgrounds'); | ||
const testPlaygroundName = 'test'; | ||
const testPlaygroundPath = nodePath.join(baseFixture, testPlaygroundName); | ||
afterEach(async () => { | ||
const baseFixture = nodePath.join('fixtures', 'playgrounds'); | ||
const testPlaygroundName = 'test'; | ||
const testPlaygroundPath = nodePath.join(baseFixture, testPlaygroundName); | ||
|
||
afterEach(async () => { | ||
await rimrafPromise(testPlaygroundPath); | ||
|
||
const testFiles = ['package-lock.json', 'node_modules', 'valid.supr.ast.json', 'valid.noop.suma.ast.json', 'valid.noop.js']; | ||
|
||
const testFiles = [ | ||
'package-lock.json', | ||
'node_modules', | ||
'valid.supr.ast.json', | ||
'valid.noop.suma.ast.json', | ||
'valid.noop.js', | ||
]; | ||
await Promise.all( | ||
testFiles.map( | ||
file => rimrafPromise(nodePath.join(baseFixture, 'valid', file)) | ||
testFiles.map(file => | ||
rimrafPromise(nodePath.join(baseFixture, 'valid', file)) | ||
) | ||
) | ||
}); | ||
); | ||
}); | ||
|
||
it('a valid playground is detected', async () => { | ||
expect( | ||
await Play.run(['clean', nodePath.join(baseFixture, 'valid')]) | ||
).toBeUndefined(); | ||
}); | ||
|
||
it('a valid playground is detected', async () => { | ||
await Play.run(['clean', nodePath.join(baseFixture, 'valid')]) | ||
}); | ||
it('an invalid playground is rejected', async () => { | ||
await expect( | ||
Play.run(['clean', nodePath.join(baseFixture, 'invalid')]) | ||
).rejects.toThrow('The directory at playground path is not a playground'); | ||
}); | ||
|
||
it('an invalid playground is rejected', async () => { | ||
await expect( | ||
Play.run(['clean', nodePath.join(baseFixture, 'invalid')]) | ||
).rejects.toThrow('The directory at playground path is not a playground') | ||
}); | ||
it('initialize creates a valid playground', async () => { | ||
await Play.run([ | ||
'initialize', | ||
testPlaygroundPath, | ||
'--providers', | ||
'foo', | ||
'bar', | ||
]); | ||
|
||
it('initialize creates a valid playground', async () => { | ||
await Play.run(['initialize', testPlaygroundPath, '--providers', 'foo', 'bar']); | ||
await accessPromise(testPlaygroundPath); | ||
|
||
await accessPromise(testPlaygroundPath); | ||
const expectedFiles = [ | ||
'package.json', | ||
'test.supr', | ||
'test.foo.suma', | ||
'test.bar.suma', | ||
'test.foo.ts', | ||
'test.bar.ts', | ||
]; | ||
for (const file of expectedFiles) { | ||
await accessPromise(nodePath.join(testPlaygroundPath, file)); | ||
} | ||
|
||
const expectedFiles = ['package.json', 'test.supr', 'test.foo.suma', 'test.bar.suma', 'test.foo.ts', 'test.bar.ts']; | ||
for (const file of expectedFiles) { | ||
await accessPromise(nodePath.join(testPlaygroundPath, file)) | ||
} | ||
// No exceptions thrown | ||
expect(undefined).toBeUndefined(); | ||
}); | ||
|
||
it('execute compiles playground and executes it', async () => { | ||
stdout.start(); | ||
await Play.run(['execute', nodePath.join(baseFixture, 'valid'), '--providers', 'noop']); | ||
await Play.run([ | ||
'execute', | ||
nodePath.join(baseFixture, 'valid'), | ||
'--providers', | ||
'noop', | ||
]); | ||
stdout.stop(); | ||
|
||
expect( | ||
stdout.output | ||
).toMatch(/pubs\/Noop result: Ok { value: \[\] }\s*$/); | ||
expect(stdout.output).toMatch(/pubs\/Noop result: Ok { value: \[\] }\s*$/); | ||
|
||
const expectedFiles = ['package-lock.json', 'node_modules', 'valid.supr.ast.json', 'valid.noop.suma.ast.json', 'valid.noop.js']; | ||
const expectedFiles = [ | ||
'package-lock.json', | ||
'node_modules', | ||
'valid.supr.ast.json', | ||
'valid.noop.suma.ast.json', | ||
'valid.noop.js', | ||
]; | ||
await Promise.all( | ||
expectedFiles.map( | ||
file => accessPromise(nodePath.join(baseFixture, 'valid', file)) | ||
expectedFiles.map(file => | ||
accessPromise(nodePath.join(baseFixture, 'valid', file)) | ||
) | ||
) | ||
); | ||
}, 30000); | ||
|
||
it('clean cleans compilation artifacts', async () => { | ||
const deletedFiles = ['package-lock.json', 'node_modules', 'test.supr.ast.json', 'test.foo.suma.ast.json', 'test.bar.suma.ast.json', 'test.foo.js', 'test.bar.js']; | ||
const expectedFiles = ['package.json', 'test.supr', 'test.foo.suma', 'test.bar.suma', 'test.foo.ts', 'test.bar.ts', 'test.baz.ts']; | ||
|
||
it('clean cleans compilation artifacts', async () => { | ||
const deletedFiles = [ | ||
'package-lock.json', | ||
'node_modules', | ||
'test.supr.ast.json', | ||
'test.foo.suma.ast.json', | ||
'test.bar.suma.ast.json', | ||
'test.foo.js', | ||
'test.bar.js', | ||
]; | ||
const expectedFiles = [ | ||
'package.json', | ||
'test.supr', | ||
'test.foo.suma', | ||
'test.bar.suma', | ||
'test.foo.ts', | ||
'test.bar.ts', | ||
'test.baz.ts', | ||
]; | ||
|
||
await mkdirPromise(testPlaygroundPath); | ||
|
||
await Promise.all( | ||
[...deletedFiles, ...expectedFiles].map( | ||
file => OutputStream.writeOnce(nodePath.join(testPlaygroundPath, file), '') | ||
[...deletedFiles, ...expectedFiles].map(file => | ||
OutputStream.writeOnce(nodePath.join(testPlaygroundPath, file), '') | ||
) | ||
); | ||
|
||
await Play.run(['clean', testPlaygroundPath]); | ||
|
||
await Promise.all( | ||
deletedFiles.map( | ||
file => expect(accessPromise(nodePath.join(testPlaygroundPath, file))).rejects.toThrowError('ENOENT') | ||
deletedFiles.map(file => | ||
expect( | ||
accessPromise(nodePath.join(testPlaygroundPath, file)) | ||
).rejects.toThrowError('ENOENT') | ||
) | ||
); | ||
|
||
await Promise.all( | ||
expectedFiles.map( | ||
file => accessPromise(nodePath.join(testPlaygroundPath, file)) | ||
expectedFiles.map(file => | ||
accessPromise(nodePath.join(testPlaygroundPath, file)) | ||
) | ||
) | ||
}); | ||
}); | ||
); | ||
}); | ||
}); |
Oops, something went wrong.