Skip to content

Commit

Permalink
feat: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaltepeter committed Oct 27, 2020
1 parent 961f02d commit 8816187
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 16 deletions.
13 changes: 9 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module.exports = {
roots: ["<rootDir>/src"],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.spec.json',
},
},
roots: ['<rootDir>/src'],
transform: {
"^.+\\.tsx?$": "ts-jest",
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
2 changes: 1 addition & 1 deletion 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 @@ -5,7 +5,7 @@
"scripts": {
"build": "tsc -p tsconfig.json && npm run copy:files",
"build:watch": "tsc -p tsconfig.json --watch && npm run copy:files",
"copy:files": "cp ./package.json dist/ && cp ./src/*.json dist/ && cp ./src/svg-icons-builder/*.json ./dist/svg-icons-builder/",
"copy:files": "cp ./src/builders.json ./src/collection.json dist/ && cp ./package.json dist/ && cp ./src/svg-icons-builder/*.json ./dist/svg-icons-builder/",
"format:write": "prettier --write ./src/**/*.ts",
"test": "jest",
"test:watch": "jest --watch"
Expand Down
2 changes: 1 addition & 1 deletion src/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';

const collectionPath = path.join(__dirname, '../collection.json');
const runner = new SchematicTestRunner('schematics', collectionPath);

describe('ng-add', () => {
it('works', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('ng-add', {}, Tree.empty()).toPromise();

expect(tree.files).toEqual([]);
Expand Down
13 changes: 13 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "svg-icons-builder",
"version": "1.0.0",
"description": "",
"private": true,
"main": "index.js",
"builders": "./builders.json",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
}
5 changes: 2 additions & 3 deletions src/svg-icons-builder/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('svg-icons-builder', () => {
beforeEach(async () => {
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const workspaceRoot = join(__dirname, '..', '..');
const workspaceRoot = join(__dirname, '..');

// TestingArchitectHost() takes workspace and current directories.
// Since we don't use those, both are the same in this case.
Expand All @@ -44,7 +44,7 @@ describe('svg-icons-builder', () => {

// A "run" can have multiple outputs, and contains progress information.
const run = await architect.scheduleBuilder(
'@angular-extensions/svg-icons-builder:svg-icons-builder',
'svg-icons-builder:svg-icons-builder',
{
...defaultCommonOptions,
conversionType: 'constants',
Expand All @@ -69,6 +69,5 @@ describe('svg-icons-builder', () => {
await run.stop();

expect(logs).toContain('We are using the conversion type "constants"');
expect(logs).toContain('svg-to-ts completed.');
});
});
5 changes: 2 additions & 3 deletions src/svg-icons-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ export default createBuilder<Options>((conversionOptions: Options, context: Buil
await convertToSingleObject((conversionOptions as unknown) as ObjectConversionOptions);
}

resolve();
resolve({ success: true });
context.reportStatus(`Done.`);
process.disconnect();
process.exit(0);
} catch (error) {
context.reportStatus('Error');
process.disconnect();
process.exit(1);
}
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"baseUrl": "tsconfig",
"baseUrl": ".",
"lib": ["es2018", "dom"],
"declaration": true,
"module": "commonjs",
Expand All @@ -18,8 +18,8 @@
"sourceMap": true,
"strictNullChecks": true,
"target": "es6",
"types": ["jest", "node"]
"types": ["node"]
},
"include": ["src/**/*"],
"exclude": ["src/*/files/**/*"]
"exclude": ["src/*/files/**/*", "src/**/*.spec.ts", "src/package.json"]
}
8 changes: 8 additions & 0 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": ["jest", "node"]
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}

0 comments on commit 8816187

Please sign in to comment.