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

test: change folder structure #712

Merged
merged 9 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
!assets/examples/default-example.yaml
!assets/examples/tutorial.yml
node_modules
/test/commands/generate/models/
/test/functionality/commands/generate/models/
asyncapi.json
asyncapi.yml
test/minimaltemplate/__transpiled
.vscode


spec-examples.zip
spec-examples.zip

# Coverage for testing

coverage
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ asyncapi/cli [COMMAND HERE]
# Example that you can run inside the cli directory after cloning this repository. First, you specify the mount in the location of your AsyncAPI specification file and then you mount it in the directory where the generation result should be saved.
docker run --rm -it \
--user=root \
-v ${PWD}/test/fixtures/asyncapi_v1.yml:/app/asyncapi.yml \
-v ${PWD}/test/functionality/fixtures/asyncapi_v1.yml:/app/asyncapi.yml \
-v ${PWD}/output:/app/output \
asyncapi/cli generate fromTemplate -o /app/output /app/asyncapi.yml @asyncapi/html-template --force-write
```
Expand Down
3 changes: 2 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
coverageReporters: [
'text'
'text',
'html'
],
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
Expand Down
101 changes: 0 additions & 101 deletions test/commands/bundle/bundle.test.ts

This file was deleted.

102 changes: 102 additions & 0 deletions test/functionality/commands/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { test } from '@oclif/test';
import fs from 'fs';
import path from 'path';
import { fileCleanup } from '../../../helpers';

const spec = fs.readFileSync('./test/functionality/commands/bundle/final-asyncapi.yaml', {encoding: 'utf-8'});
const asyncapiv3 = './test/functionality/specification-v3.yml';

function validateGeneratedSpec(filePath, spec) {
const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' });
return generatedSPec === spec;
}

describe('bundle', () => {
describe('should handle AsyncAPI v3 document correctly', () => {
test
.stderr()
.stdout()
.command([
'bundle',
asyncapiv3,
'--output=./test/functionality/commands/bundle/final.yaml'])
.it('give error', (ctx, done) => {
expect(ctx.stderr).toEqual('Error: One of the files you tried to bundle is AsyncAPI v3 format, the bundle command does not support it yet, please checkout https://github.com/asyncapi/bundler/issues/133\n');
expect(ctx.stdout).toEqual('');
done();
});
});

test
.stdout()
.command([
'bundle', './test/functionality/commands/bundle/first-asyncapi.yaml',
'--output=./test/functionality/commands/bundle/final.yaml',
])
.it('should successfully bundle specification', (ctx, done) => {
expect(ctx.stdout).toContain(
'Check out your shiny new bundled files at ./test/functionality/commands/bundle/final.yaml'
);
fileCleanup('./test/functionality/commands/bundle/final.yaml');
done();
});

test
.stdout()
.command([
'bundle', './test/functionality/commands/bundle/first-asyncapi.yaml',
'--output=./test/functionality/commands/bundle/final.json'
])
.it('should successfully bundle specification into json file', (ctx, done) => {
expect(ctx.stdout).toContain(
'Check out your shiny new bundled files at ./test/functionality/commands/bundle/final.json'
);
fileCleanup('./test/functionality/commands/bundle/final.json');
done();
});

test
.stderr()
.command([
'bundle', './test/functionality/commands/bundle/asyncapi.yml'
])
.it('should throw error message if the file path is wrong', (ctx, done) => {
expect(ctx.stderr).toContain('error loading AsyncAPI document from file: ./test/functionality/commands/bundle/asyncapi.yml file does not exist.\n');
done();
});

test
.stdout()
.command([
'bundle', './test/functionality/commands/bundle/first-asyncapi.yaml', '--reference-into-components', '--output=./test/functionality/commands/bundle/final.yaml'
])
.it('should be able to refence messages into components', (ctx, done) => {
expect(ctx.stdout).toContain('Check out your shiny new bundled files at ./test/functionality/commands/bundle/final.yaml\n');
fileCleanup('./test/functionality/commands/bundle/final.yaml');
done();
});

test
.stdout()
.command([
'bundle', './test/functionality/commands/bundle/first-asyncapi.yaml', './test/functionality/commands/bundle/feature.yaml', '--reference-into-components', '--output=test/functionality/commands/bundle/final.yaml'
])
.it('should be able to bundle multiple specs along with custom reference', (ctx, done) => {
expect(ctx.stdout).toContain('Check out your shiny new bundled files at test/functionality/commands/bundle/final.yaml\n');
expect(validateGeneratedSpec('test/functionality/commands/bundle/final.yaml', spec));
fileCleanup('./test/functionality/commands/bundle/final.yaml');
done();
});

test
.stdout()
.command([
'bundle', './test/functionality/commands/bundle/first-asyncapi.yaml', './test/functionality/commands/bundle/feature.yaml', '--reference-into-components', '--output=test/functionality/commands/bundle/final.yaml', '--base=./test/functionality/commands/bundle/first-asyncapi.yaml'
])
.it('should be able to bundle correctly with overwriting base file', (ctx, done) => {
expect(ctx.stdout).toContain('Check out your shiny new bundled files at test/functionality/commands/bundle/final.yaml\n');
expect(validateGeneratedSpec('test/functionality/commands/bundle/final-asyncapi.yaml', spec));
fileCleanup('./test/functionality/commands/bundle/final.yaml');
done();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ channels:
user/loggedOut:
subcribe:
message:
$ref: 'test/commands/bundle/messages.yaml#/messages/UserLoggedOut'
$ref: 'test/functionality/commands/bundle/messages.yaml#/messages/UserLoggedOut'

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ channels:
user/signedup:
subscribe:
message:
$ref: "./test/commands/bundle/messages.yaml#/messages/UserSignedUp"
$ref: "./test/functionality/commands/bundle/messages.yaml#/messages/UserSignedUp"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { test } from '@oclif/test';

import TestHelper from '../testHelper';
import TestHelper from '../../helpers';

const testHelper = new TestHelper();

Expand Down Expand Up @@ -44,7 +44,7 @@ describe('config', () => {
test
.stderr()
.stdout()
.command(['config:context:add', 'test', './test/specification.yml'])
.command(['config:context:add', 'test', './test/functionality/specification.yml'])
.it('should add new context called "test"', (ctx, done) => {
expect(ctx.stdout).toEqual(
'Added context "test".\n\nYou can set it as your current context: asyncapi config context use test\nYou can use this context when needed by passing test as a parameter: asyncapi validate test\n'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path';
import { test } from '@oclif/test';
import { NO_CONTEXTS_SAVED } from '../../src/errors/context-error';
import TestHelper, { createMockServer, stopMockServer } from '../testHelper';
import { NO_CONTEXTS_SAVED } from '../../../src/errors/context-error';
import TestHelper, { createMockServer, stopMockServer } from '../../helpers';
import fs from 'fs-extra';

const testHelper = new TestHelper();
const filePath = './test/specification.yml';
const JSONFilePath = './test/specification.json';
const filePath = './test/functionality/specification.yml';
const JSONFilePath = './test/functionality/specification.json';

describe('convert', () => {
describe('with file paths', () => {
Expand All @@ -31,18 +31,18 @@ describe('convert', () => {
.stdout()
.command(['convert', filePath])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stdout).toContain('File ./test/specification.yml successfully converted!\n');
expect(ctx.stdout).toContain('File ./test/functionality/specification.yml successfully converted!\n');
expect(ctx.stderr).toEqual('');
done();
});

test
.stderr()
.stdout()
.command(['convert', './test/not-found.yml'])
.command(['convert', './test/functionality/not-found.yml'])
.it('should throw error if file path is wrong', (ctx, done) => {
expect(ctx.stdout).toEqual('');
expect(ctx.stderr).toEqual('error loading AsyncAPI document from file: ./test/not-found.yml file does not exist.\n');
expect(ctx.stderr).toEqual('error loading AsyncAPI document from file: ./test/functionality/not-found.yml file does not exist.\n');
done();
});

Expand Down Expand Up @@ -156,24 +156,24 @@ describe('convert', () => {
test
.stderr()
.stdout()
.command(['convert', filePath, '-o=./test/specification_output.yml'])
.command(['convert', filePath, '-o=./test/functionality/specification_output.yml'])
.it('works when .yml file is passed', (ctx, done) => {
expect(ctx.stdout).toEqual(`File ${filePath} successfully converted!\n`);
expect(fs.existsSync('./test/specification_output.yml')).toBe(true);
expect(fs.existsSync('./test/functionality/specification_output.yml')).toBe(true);
expect(ctx.stderr).toEqual('');
fs.unlinkSync('./test/specification_output.yml');
fs.unlinkSync('./test/functionality/specification_output.yml');
done();
});

test
.stderr()
.stdout()
.command(['convert', JSONFilePath, '-o=./test/specification_output.json'])
.command(['convert', JSONFilePath, '-o=./test/functionality/specification_output.json'])
.it('works when .json file is passed', (ctx, done) => {
expect(ctx.stdout).toEqual(`File ${JSONFilePath} successfully converted!\n`);
expect(fs.existsSync('./test/specification_output.json')).toBe(true);
expect(fs.existsSync('./test/functionality/specification_output.json')).toBe(true);
expect(ctx.stderr).toEqual('');
fs.unlinkSync('./test/specification_output.json');
fs.unlinkSync('./test/functionality/specification_output.json');
done();
});
});
Expand Down
Loading