import { VirtualTree, SchematicContext, MergeStrategy, Tree } from '@angular-devkit/schematics'; import { updateTravis } from './update.travis'; import { Schema } from './schema'; import { isObservable, of } from 'rxjs'; import { tap } from 'rxjs/operators'; import { getFileContent } from '../test'; import { safeDump, safeLoad } from 'js-yaml'; describe('update.travis', () => { const context: SchematicContext = ({ engine: null, debug: false, strategy: MergeStrategy.Default } as {}) as SchematicContext; it('should update an existing travis file', () => { const tree = new VirtualTree(); const options: Schema = { url: 'http:/example.org' }; const OLD_TRAVIS_TEMPLATE = { node_js: ['8'], language: 'node_js', script: ['npm run deploy'] }; tree.create('.travis.yml', safeDump(OLD_TRAVIS_TEMPLATE)); const res = updateTravis(options)(tree, context); const rxRes = isObservable(res) ? res : of(res as Tree); return rxRes .pipe( tap(tree => { // verify the url expect(tree).toBeTruthy(); if (tree) { // check that we have the file expect(tree.exists('/.travis.yml')).toBeTruthy(); // parse const travis = safeLoad( getFileContent(tree, '/.travis.yml') ) as any; expect(travis.branches).toBeTruthy(); } }) ) .toPromise(); }); it('should create a new travis file', () => { const tree = new VirtualTree(); const options: Schema = { url: 'http:/example.org' }; const res = updateTravis(options)(tree, context); const rxRes = isObservable(res) ? res : of(res as Tree); return rxRes .pipe( tap(tree => { // verify the url expect(tree).toBeTruthy(); if (tree) { // check that we have the file expect(tree.exists('/.travis.yml')).toBeTruthy(); } }) ) .toPromise(); }); });