Skip to content

Commit

Permalink
use webpack context for ng example
Browse files Browse the repository at this point in the history
  • Loading branch information
kolodny committed Feb 26, 2024
1 parent e4b8832 commit f57bb0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 10 additions & 3 deletions examples/angular-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ const importer2 = (s: string) => import(`./${s}.safetest`);
// declarations: [],
// });

const webpackContext = import.meta.webpackContext('.', {
recursive: true,
regExp: /\.safetest$/,
mode: 'lazy',
});

const keys = webpackContext.keys();
webpackContext.keys = () => keys.filter((k) => k.startsWith('./'));

bootstrap({
platformBrowserDynamic,
import: (s) =>
import(`${s.replace(/.*src/, '.').replace(/\.safetest$/, '')}.safetest`),
// Module: AppModule,
webpackContext,
Module: AppModule,
});

Expand Down
12 changes: 8 additions & 4 deletions src/ng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ export const makeSafetestBed = (
actualNg = ng;
const { TestBed } = await renderArgsValue.TestBed;
const DynamicTesting = await renderArgsValue.DynamicTesting;
TestBed.initTestEnvironment(
DynamicTesting.BrowserDynamicTestingModule,
DynamicTesting.platformBrowserDynamicTesting()
);
const safetestHash = window.location.hash.includes('safetest');
// When #safetest is used we want to import all the test files but not run them.
if (!safetestHash) {
TestBed.initTestEnvironment(
DynamicTesting.BrowserDynamicTestingModule,
DynamicTesting.platformBrowserDynamicTesting()
);
}
});

let renderMeta: undefined | TestModuleMetadata = undefined;
Expand Down

0 comments on commit f57bb0f

Please sign in to comment.