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 all 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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ dist
lib
/test/commands/generate/models/
test/helpers
/test/minimaltemplate
/test/fixtures/minimaltemplate
create-glee-app
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
!assets/examples/default-example.yaml
!assets/examples/tutorial.yml
node_modules
/test/commands/generate/models/
/test/integration/generate/models/
asyncapi.json
asyncapi.yml
test/minimaltemplate/__transpiled
test/fixtures/minimaltemplate/__transpiled
.vscode


oclif.manifest.json
spec-examples.zip
spec-examples.zip

# Coverage for testing

coverage
4 changes: 2 additions & 2 deletions assets/create-glee-app/templates/default/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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/integration/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
18 changes: 12 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ws": "^8.2.3"
},
"devDependencies": {
"@asyncapi/minimaltemplate": "./test/minimaltemplate",
"@asyncapi/minimaltemplate": "./test/fixtures/minimaltemplate",
"@babel/core": "^7.19.3",
"@jest/types": "^29.1.0",
"@oclif/test": "^2",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"description": "Custom version to be used"
},
"mode": {
"description": "developement or production"
"description": "development or production"
}
}
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions test/testHelper.ts → test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { existsSync, writeFileSync, unlinkSync, rmSync, mkdirSync , promises as fs } from 'fs';
import * as path from 'path';
import { IContextFile, CONTEXT_FILE_PATH } from '../src/models/Context';
import SpecificationFile from '../src/models/SpecificationFile';
import { IContextFile, CONTEXT_FILE_PATH } from '../../src/models/Context';
import SpecificationFile from '../../src/models/SpecificationFile';
import http from 'http';

const ASYNCAPI_FILE_PATH = path.resolve(process.cwd(), 'specification.yaml');
const SERVER_DIRECTORY= path.join(__dirname, 'dummyspec');
const SERVER_DIRECTORY= path.join(__dirname, '../fixtures/dummyspec');
export const PROJECT_DIRECTORY_PATH = path.join(process.cwd(), 'test-project');

let server: http.Server;

export default class ContextTestingHelper {
private _context: IContextFile;
constructor() {
const homeSpecFile = new SpecificationFile(path.resolve(__dirname, 'specification.yml'));
const homeSpecFile = new SpecificationFile(path.resolve(__dirname, '../fixtures/specification.yml'));

const codeSpecFile = new SpecificationFile(path.resolve(__dirname, 'specification.yml'));
const codeSpecFile = new SpecificationFile(path.resolve(__dirname, '../fixtures/specification.yml'));
this._context = {
current: 'home',
store: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { test } from '@oclif/test';
import fs from 'fs';
import path from 'path';
import { fileCleanup } from '../../testHelper';
import { fileCleanup } from '../../helpers';

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

function validateGeneratedSpec(filePath, spec) {
const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' });
Expand All @@ -19,83 +19,84 @@ describe('bundle', () => {
.command([
'bundle',
asyncapiv3,
'--output=./test/commands/bundle/final.yaml'])
'--output=./test/integration/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:/asyncapi/bundler/issues/133\n');
expect(ctx.stdout).toEqual('');
done();
});
});

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

test
.stdout()
.command([
'bundle', './test/commands/bundle/first-asyncapi.yaml',
'--output=./test/commands/bundle/final.json'
'bundle', './test/integration/bundle/first-asyncapi.yaml',
'--output=./test/integration/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/commands/bundle/final.json'
'Check out your shiny new bundled files at ./test/integration/bundle/final.json'
);
fileCleanup('./test/commands/bundle/final.json');
fileCleanup('./test/integration/bundle/final.json');
done();
});

test
.stderr()
.command([
'bundle', './test/commands/bundle/asyncapi.yml'
'bundle', './test/integration/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/commands/bundle/asyncapi.yml file does not exist.\n');
expect(ctx.stderr).toContain('error loading AsyncAPI document from file: ./test/integration/bundle/asyncapi.yml file does not exist.\n');
done();
});

test
.stdout()
.command([
'bundle', './test/commands/bundle/first-asyncapi.yaml', '--reference-into-components', '--output=test/commands/bundle/final.yaml'
'bundle', './test/integration/bundle/first-asyncapi.yaml', '--reference-into-components', '--output=./test/integration/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/commands/bundle/final.yaml\n');
fileCleanup('./test/commands/bundle/final.yaml');
expect(ctx.stdout).toContain('Check out your shiny new bundled files at ./test/integration/bundle/final.yaml\n');
fileCleanup('./test/integration/bundle/final.yaml');
done();
});

test
.stdout()
.command([
'bundle', './test/commands/bundle/first-asyncapi.yaml', './test/commands/bundle/feature.yaml', '--reference-into-components', '--output=test/commands/bundle/final.yaml'
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--reference-into-components', '--output=test/integration/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/commands/bundle/final.yaml\n');
expect(validateGeneratedSpec('test/commands/bundle/final.yaml', spec));
fileCleanup('./test/commands/bundle/final.yaml');
expect(ctx.stdout).toContain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n');
expect(validateGeneratedSpec('test/integration/bundle/final.yaml', spec));
fileCleanup('./test/integration/bundle/final.yaml');
done();
});

test
.stdout()
.command([
'bundle', './test/commands/bundle/first-asyncapi.yaml', './test/commands/bundle/feature.yaml', '--reference-into-components', '--output=test/commands/bundle/final.yaml', '--base=./test/commands/bundle/first-asyncapi.yaml'
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--reference-into-components', '--output=test/integration/bundle/final.yaml', '--base=./test/integration/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/commands/bundle/final.yaml\n');
expect(validateGeneratedSpec('test/commands/bundle/final-asyncapi.yaml', spec));
fileCleanup('./test/commands/bundle/final.yaml');
expect(ctx.stdout).toContain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n');
expect(validateGeneratedSpec('test/integration/bundle/final-asyncapi.yaml', spec));
fileCleanup('./test/integration/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/integration/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/integration/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';
import { CONTEXT_FILE_PATH } from '../../src/models/Context';

const testHelper = new TestHelper();
Expand Down Expand Up @@ -47,8 +47,8 @@ describe('config:context, positive scenario', () => {
expect(ctx.stdout).toEqual(
`home: ${path.resolve(
__dirname,
'../specification.yml'
)}\ncode: ${path.resolve(__dirname, '../specification.yml')}\n`
'../fixtures/specification.yml'
)}\ncode: ${path.resolve(__dirname, '../fixtures/specification.yml')}\n`
);
expect(ctx.stderr).toEqual('');
done();
Expand All @@ -60,7 +60,7 @@ describe('config:context, positive scenario', () => {
test
.stderr()
.stdout()
.command(['config:context:add', 'test', './test/specification.yml'])
.command(['config:context:add', 'test', './test/integration/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
Loading