Skip to content

Instantly share code, notes, and snippets.

@MSakamaki
Last active December 28, 2021 01:20
Show Gist options
  • Save MSakamaki/049a1fd82e9305d459b3952e36150401 to your computer and use it in GitHub Desktop.
Save MSakamaki/049a1fd82e9305d459b3952e36150401 to your computer and use it in GitHub Desktop.
nrwl/nx chips
import { readFile, writeFileSync } from 'fs';
(async () => {
const nxJson: { [id: string]: object } = JSON.parse(
await new Promise((r, j) =>
readFile('./nx.json', 'utf-8', (e, data) => (e ? j(e) : r(data)))
)
);
const angularJson: { [id: string]: object } = JSON.parse(
await new Promise((r, j) =>
readFile('./angular.json', 'utf-8', (e, data) => (e ? j(e) : r(data)))
)
);
const newAngularJsonProjects = Object.entries(angularJson.projects).reduce(
(origin, [project, config]) => {
console.log('project', project);
return {
...origin,
[project]: {
...config,
tags: nxJson.projects[project].tags || [],
architect: {
...config.architect,
lint: {
...config.architect.lint,
outputs: ['{options.outputFile}'],
options: {
...config.architect.lint.options,
lintFilePatterns:
config.architect.lint.options.lintFilePatterns.map((lfp) =>
lfp.replace('/*.ts', '/*.{js,ts}')
),
},
},
},
},
};
},
{}
);
writeFileSync(
'./angular.json.new',
JSON.stringify(
{
...angularJson,
projects: newAngularJsonProjects,
},
null,
2
)
);
})();
/**
 * Create test action for dataPersistence.navigation
 */
export function CreateDataPersistenceNavigater(component: any, params: any = {}) {
  return {
    a: {
      type: 'ROUTER_NAVIGATION',
      payload: {
        routerState: {
          root: {
            routeConfig: {
              component: component
            },
            params: params,
          },
        }
      }
    }
  }
}

use

    it(
      'should work navigate.FrameComponent',
      async(async () => {
        actions = hot('-a-|', CreateDataPersistenceNavigater(FrameComponent, { test: 'sample' }));
        expect(await readAll(effects.loadData)).toEqual([{ type: 'DATA_LOADED', payload: {} }]);
      })
    );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment