2

I am trying to test my schematic, which requires some initial setup of other schematics (creating a workspace and application) and I want to see only the changes that my schematic makes (not the changes to everything)

Setup:


    // Create the workspace
    appTree = runner.runExternalSchematic('@schematics/angular', 'workspace', workspaceOptions);
    // Create the app
    appTree = runner.runExternalSchematic('@schematics/angular', 'application', appOptions, appTree);
    // Create a test component
    appTree = runner.runExternalSchematic(
      '@schematics/angular',
      'component',
      {name: 'foo', project: appOptions.name} as ComponentOptions,
      appTree
    );

After some digging, I found tree.actions allows you to see what has changed on the tree, but it shows all the actions (including the creation of all the Angular stuff)

Test:


    it('makes changes', () => {
      // Do something to appTree to "commit" changes
      const tree = runner.runSchematic('my-schematic', {}, appTree);
      // I want `tree.actions` to just show the changes from 'my-schematic'
    });

What I want is a way to "commit" the changes to the tree after making all the changes to setup the workspace, app, and component so I can just see the changes and test off of that.

Is there something in the Angular test suite or the general schematics API that would let me do this?

jamesthollowell
  • 1,550
  • 15
  • 21
  • I'm very interested in this as well. I've found working with schematics a bit bothersome on the development side as I also wasn't able to figure out how to run a schematic on an app *before* publishing it to a registry… being able to do this via tests would be even better. – Ingo Bürk Jan 10 '19 at 20:32
  • @IngoBürk you can use the schematic without publishing it by doing `yarn link` in the schematics dir and then `yarn link ` in the main project directory – jamesthollowell Jan 10 '19 at 21:52

0 Answers0