Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function createFileSystemTestApp(runner: SchematicTestRunner) {
const tempFileSystemHost = new TempScopedNodeJsSyncHost();
const hostTree = new HostTree(tempFileSystemHost);
const appTree: UnitTestTree = await createTestApp(runner, {name: 'cdk-testing'}, hostTree);
const tempPath = getSystemPath(tempFileSystemHost.root);
// Since the TypeScript compiler API expects all files to be present on the real file system, we
// map every file in the app tree to a temporary location on the file system.
appTree.files.forEach(f => writeFile(f, appTree.readContent(f)));
return {
appTree,
tempFileSystemHost,
tempPath,
writeFile,
removeTempDir: () => removeSync(tempPath),
};
function writeFile(filePath: string, content: string) {
describe('@schematics/update', () => {
const schematicRunner = new SchematicTestRunner(
'@schematics/update',
require.resolve('../collection.json'),
);
let host: virtualFs.test.TestHost;
let appTree: UnitTestTree = new UnitTestTree(new HostTree());
beforeEach(() => {
host = new virtualFs.test.TestHost({
'/package.json': `{
"name": "blah",
"dependencies": {
"@angular-devkit-tests/update-base": "1.0.0"
}
}`,
});
appTree = new UnitTestTree(new HostTree(host));
});
it('updates package.json', done => {
// Since we cannot run tasks in unit tests, we need to validate that the default
// update schematic updates the package.json appropriately, AND validate that the
it('should show error when there is a missing config file', () => {
const xliffmergeProject: ProjectOptions = {
name: 'projectWithXliffmerge'
};
const packageOptions: PackageJsonOptions = {
project: xliffmergeProject.name,
createExtractScriptCommandline: true,
xliffmergeConfigFilePath: 'test/xliffmerge.config',
languages: ['en', 'de']
};
host = createHost([xliffmergeProject], [packageOptions], []);
appTree = new UnitTestTree(new HostTree(host));
let loggerOutput = '';
testRunner.logger.subscribe(entry => {
loggerOutput = loggerOutput + entry.message;
});
appTree = testRunner.runSchematic('update-1', defaultOptions, appTree);
expect(loggerOutput).toContain('Could not find config file "//test/xliffmerge.config"');
});
function getTree(files: File[] = []) {
const tree = new HostTree();
files.forEach(({ path, content = '' }) => {
tree.create(path, content);
});
return tree;
}
function withFiles(source: string, ignore: string[], SOURCE_FILES: string[]) {
beforeEach(() => {
host = new virtualFs.test.TestHost({
'/package.json': `{
"name": "blah",
"dependencies": {
"@angular-devkit-tests/update-base": "1.0.0"
}
}`,
});
appTree = new UnitTestTree(new HostTree(host));
});
beforeEach(() => {
appTree = new UnitTestTree(new HostTree());
});
async function readDefaultCollection(host: virtualFs.Host) {
const workspaceJson = JSON.parse(
new HostTree(host).read('workspace.json')!.toString()
);
return workspaceJson.cli ? workspaceJson.cli.defaultCollection : null;
}
function applyChanges(path: string, content: string, changes: Change[]): string {
const tree = new HostTree();
tree.create(path, content);
const exportRecorder = tree.beginUpdate(path);
for (const change of changes) {
if (change instanceof InsertChange) {
exportRecorder.insertLeft(change.pos, change.toAdd);
}
}
tree.commitUpdate(exportRecorder);
return getFileContent(tree, path);
}
beforeEach(() => {
tree = new UnitTestTree(new HostTree());
});