Skip to content

Commit

Permalink
test(core): add test for exists and fix test in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Jun 7, 2021
1 parent 67bff3b commit 737ea43
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"pretty-quick": "^2.0.1",
"protractor": "~7.0.0",
"rimraf": "^3.0.2",
"temp": "^0.9.4",
"ts-node": "8.7.0",
"tslint": "~6.1.0",
"typemoq": "^2.1.0",
Expand Down
30 changes: 30 additions & 0 deletions packages/core/src/fs/node-host.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DocgeniNodeJsAsyncHost } from './node-host';
import { normalize, virtualFs } from '@angular-devkit/core';
import { NodeJsAsyncHost } from '@angular-devkit/core/node';
import fs from 'fs';
import temp from 'temp';

describe('DocgeniNodeJsAsyncHost', () => {
let root: string;
let host: virtualFs.Host<fs.Stats>;

beforeEach(() => {
root = temp.mkdirSync('core-node-spec-');
host = new virtualFs.ScopedHost(new DocgeniNodeJsAsyncHost(), normalize(root));
});

afterEach(done =>
host
.delete(normalize('/'))
.toPromise()
.then(done, done.fail)
);

it('should get correct result for exists', async () => {
let isExists = await host.exists(normalize('not-found')).toPromise();
expect(isExists).toBe(false);
await host.write(normalize('not-found'), virtualFs.stringToFileBuffer('content')).toPromise();
isExists = await host.exists(normalize('not-found')).toPromise();
expect(isExists).toBe(true);
});
});
5 changes: 3 additions & 2 deletions packages/core/test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toolkit } from '@docgeni/toolkit';
import { createTestDocgeniHost, expectThrowAsync } from './utils';
import { DocgeniHost } from '../src/docgeni-host';
import path from 'path';
import { virtualFs, normalize } from '@angular-devkit/core';
import { virtualFs, normalize, getSystemPath } from '@angular-devkit/core';

describe('#config', () => {
let docgeniHost: DocgeniHost;
Expand Down Expand Up @@ -185,6 +185,7 @@ describe('#config', () => {

it('should throw error when doc dir has not exists', async () => {
const notFoundPath = 'not-found/path';
const expectFullPath = normalize(`${process.cwd()}/${notFoundPath}`);
await expectThrowAsync(async () => {
const docgeni = new Docgeni({
config: {
Expand All @@ -193,7 +194,7 @@ describe('#config', () => {
host: docgeniHost
});
await docgeni.verifyConfig();
}, `docs dir(${notFoundPath}) has not exists, full path: ${process.cwd()}/${notFoundPath}`);
}, `docs dir(${notFoundPath}) has not exists, full path: ${getSystemPath(expectFullPath)}`);
docgeniHost.writeFile(`${process.cwd()}/${notFoundPath}/index.md`, 'content');
await new Docgeni({
config: {
Expand Down
5 changes: 3 additions & 2 deletions packages/toolkit/test/template.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { toolkit, fs } from '../src';
import * as path from 'path';
import { expect } from 'chai';
import { EOL } from 'os';

describe('#toolkit.template', () => {
beforeEach(() => {
Expand All @@ -13,7 +14,7 @@ describe('#toolkit.template', () => {
const result = toolkit.template.compile('module.hbs', {
name: 'First Name'
});
expect(result).eq('This is template First Name\n');
expect(result).eq(`This is template First Name${EOL}`);
});

it('should compile json success', () => {
Expand Down Expand Up @@ -42,7 +43,7 @@ describe('#toolkit.template', () => {
"path": "getting-started"
}
]
};\n`;
};${EOL}`;
expect(result).eq(expected);
});
});
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12536,6 +12536,13 @@ rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.2, rimraf@^2.6.3, rimra
dependencies:
glob "^7.1.3"

rimraf@~2.6.2:
version "2.6.3"
resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
dependencies:
glob "^7.1.3"

ripemd160@^2.0.0, ripemd160@^2.0.1:
version "2.0.2"
resolved "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c"
Expand Down Expand Up @@ -13785,6 +13792,14 @@ temp-write@^3.4.0:
temp-dir "^1.0.0"
uuid "^3.0.1"

temp@^0.9.4:
version "0.9.4"
resolved "https://registry.npmjs.org/temp/-/temp-0.9.4.tgz#cd20a8580cb63635d0e4e9d4bd989d44286e7620"
integrity sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==
dependencies:
mkdirp "^0.5.1"
rimraf "~2.6.2"

terser-webpack-plugin@4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-4.1.0.tgz#6e9d6ae4e1a900d88ddce8da6a47507ea61f44bc"
Expand Down

0 comments on commit 737ea43

Please sign in to comment.