Skip to content

Commit

Permalink
fix: switch from jest to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal committed Oct 1, 2023
1 parent 385842d commit d90ab36
Show file tree
Hide file tree
Showing 17 changed files with 1,239 additions and 1,814 deletions.
2,400 changes: 904 additions & 1,496 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@
"devDependencies": {
"@asyncapi/minimaltemplate": "./test/fixtures/minimaltemplate",
"@babel/core": "^7.19.3",
"@jest/types": "^29.1.0",
"@oclif/test": "^2",
"@swc/core": "^1.3.2",
"@swc/jest": "^0.2.22",
"@types/chai": "^4.3.3",
"@types/chai": "^4.3.6",
"@types/fs-extra": "^11.0.1",
"@types/inquirer": "^8.1.3",
"@types/jest": "^29.0.3",
"@types/js-yaml": "^4.0.5",
"@types/lodash.template": "^4.4.4",
"@types/mocha": "^10.0.2",
"@types/node": "^10.17.60",
"@types/node-fetch": "^2.5.12",
"@types/rimraf": "^3.0.2",
Expand All @@ -73,8 +71,9 @@
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-sonarjs": "^0.15.0",
"globby": "^10.0.2",
"jest": "^29.1.0",
"markdown-toc": "^1.2.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"rimraf": "^3.0.2",
Expand Down Expand Up @@ -144,11 +143,12 @@
"pack:windows": "oclif pack win && npm run pack:rename",
"pack:rename": "node scripts/releasePackagesRename.js",
"prepublishOnly": "npm run build",
"pretest": "npm run build",
"posttest": "rimraf ./test.asyncapi-cli",
"pretest:coverage": "npm run build",
"release": "semantic-release",
"pretest": "npm run build",
"test": "npm run test:unit",
"test:unit": "cross-env NODE_ENV=development TEST=1 CUSTOM_CONTEXT_FILENAME=\"test.asyncapi-cli\" CUSTOM_CONTEXT_FILE_LOCATION=\"\" jest --coverage -i",
"test:unit": "cross-env NODE_ENV=development TEST=1 CUSTOM_CONTEXT_FILENAME=\"test.asyncapi-cli\" CUSTOM_CONTEXT_FILE_LOCATION=\"\" nyc --extension .ts mocha --require ts-node/register --require test/helpers/init.js --reporter spec --timeout 100000 \"test/**/*.test.ts\"",
"get-version": "echo $npm_package_version"
},
"types": "lib/index.d.ts"
Expand Down
11 changes: 6 additions & 5 deletions test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { existsSync, writeFileSync, unlinkSync, rmSync, mkdirSync , promises as fs } from 'fs';
import { existsSync, writeFileSync, unlinkSync,rmdirSync, 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 http from 'http';
import rimraf from 'rimraf';

const ASYNCAPI_FILE_PATH = path.resolve(process.cwd(), 'specification.yaml');
const SERVER_DIRECTORY= path.join(__dirname, '../fixtures/dummyspec');
Expand Down Expand Up @@ -39,7 +40,7 @@ export default class ContextTestingHelper {

deleteDummyContextFile(): void {
if (existsSync(CONTEXT_FILE_PATH)) {
rmSync(CONTEXT_FILE_PATH);
unlinkSync(CONTEXT_FILE_PATH);
}
}

Expand Down Expand Up @@ -83,12 +84,12 @@ export default class ContextTestingHelper {
}

deleteDummyProjectDirectory(): void {
rmSync(PROJECT_DIRECTORY_PATH, { recursive: true, force: true });
rimraf.sync(PROJECT_DIRECTORY_PATH);
}
}

export function fileCleanup(filepath: string) {
rmSync(filepath);
unlinkSync(filepath);
}

export function createMockServer (port = 8080) {
Expand All @@ -99,7 +100,7 @@ export function createMockServer (port = 8080) {
const content = await fs.readFile(filePath, {encoding: 'utf8'});
res.writeHead(200, {'Content-Type': getContentType(filePath)});
res.end(content);
} catch (error) {
} catch (error: any) {
if (error.code === 'ENOENT') {
res.writeHead(404);
res.end('404 NOT FOUND');
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');
process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json');
process.env.NODE_ENV = 'development';

global.oclif = global.oclif || {};
global.oclif.columns = 80;

require('events').EventEmitter.defaultMaxListeners = 30;
20 changes: 10 additions & 10 deletions test/integration/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test } from '@oclif/test';
import { expect, test } from '@oclif/test';
import fs from 'fs';
import path from 'path';
import { fileCleanup } from '../../helpers';

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

function validateGeneratedSpec(filePath, spec) {
function validateGeneratedSpec(filePath: string, spec: string) {
const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' });
return generatedSPec === spec;
}
Expand All @@ -21,8 +21,8 @@ describe('bundle', () => {
asyncapiv3,
'--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://github.com/asyncapi/bundler/issues/133\n');
expect(ctx.stdout).toEqual('');
expect(ctx.stderr).to.equal('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).to.equal('');
done();
});
});
Expand All @@ -34,7 +34,7 @@ describe('bundle', () => {
'--output=./test/integration/bundle/final.yaml',
])
.it('should successfully bundle specification', (ctx, done) => {
expect(ctx.stdout).toContain(
expect(ctx.stdout).to.contain(
'Check out your shiny new bundled files at ./test/integration/bundle/final.yaml'
);
fileCleanup('./test/integration/bundle/final.yaml');
Expand All @@ -48,7 +48,7 @@ describe('bundle', () => {
'--output=./test/integration/bundle/final.json'
])
.it('should successfully bundle specification into json file', (ctx, done) => {
expect(ctx.stdout).toContain(
expect(ctx.stdout).to.contain(
'Check out your shiny new bundled files at ./test/integration/bundle/final.json'
);
fileCleanup('./test/integration/bundle/final.json');
Expand All @@ -61,7 +61,7 @@ describe('bundle', () => {
'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/integration/bundle/asyncapi.yml file does not exist.\n');
expect(ctx.stderr).to.contain('error loading AsyncAPI document from file: ./test/integration/bundle/asyncapi.yml file does not exist.\n');
done();
});

Expand All @@ -71,7 +71,7 @@ describe('bundle', () => {
'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/integration/bundle/final.yaml\n');
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at ./test/integration/bundle/final.yaml\n');
fileCleanup('./test/integration/bundle/final.yaml');
done();
});
Expand All @@ -82,7 +82,7 @@ describe('bundle', () => {
'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/integration/bundle/final.yaml\n');
expect(ctx.stdout).to.contain('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();
Expand All @@ -94,7 +94,7 @@ describe('bundle', () => {
'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/integration/bundle/final.yaml\n');
expect(ctx.stdout).to.contain('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();
Expand Down
14 changes: 7 additions & 7 deletions test/integration/config/versions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '@oclif/test';
import { expect, test } from '@oclif/test';

describe('config', () => {
describe('config:versions', () => {
Expand All @@ -7,10 +7,10 @@ describe('config', () => {
.stdout()
.command(['config:versions'])
.it('should show versions of AsyncAPI tools used', (ctx, done) => {
expect(ctx.stdout).toContain('@asyncapi/cli/');
expect(ctx.stdout).toContain('├@asyncapi/');
expect(ctx.stdout).toContain('└@asyncapi/');
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).to.contain('@asyncapi/cli/');
expect(ctx.stdout).to.contain('├@asyncapi/');
expect(ctx.stdout).to.contain('└@asyncapi/');
expect(ctx.stderr).to.equal('');
done();
});

Expand All @@ -19,8 +19,8 @@ describe('config', () => {
.stdout()
.command(['config:versions'])
.it('should show address of repository of AsyncAPI CLI', (ctx, done) => {
expect(ctx.stdout).toContain('https://github.com/asyncapi/cli');
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).to.contain('https://github.com/asyncapi/cli');
expect(ctx.stderr).to.equal('');
done();
});
});
Expand Down
Loading

0 comments on commit d90ab36

Please sign in to comment.