我希望有一个仅在Angular CLI应用程序中运行e2e测试时才构建并提供的静态(非Angular)html文件。在生产应用程序中,该静态文件不可用。
我正在尝试以最小的复制使它起作用,但是看不到我该怎么做。我首先创建一个具有所有默认设置的ng new
(Angular CLI 7.3.9)应用程序。然后,我这样做了:
"src/production-static-page.html",
文件中的"assets"
主条目下的angular.json
中添加projects
。<p id="foo">bar</p>
作为内容创建了该文件。对此进行了扩展的e2e支架测试:
it('can navigate to e2e-only html', () => {
browser.waitForAngularEnabled(false);
browser.get('/e2e-only-static-page.html');
const text = element(by.css('#foo')).getText();
expect(text).toEqual('bar');
browser.waitForAngularEnabled(true);
});
那是可行的,因为该html文件只是普通的生产文件,因此当我将应用程序部署到生产中时也可以使用该文件。
我看不到应该如何在"foo-bar-e2e"
文件中配置angular.json
项目的方式,以便仅将另一个html文件(例如e2e-only-static-page.html
)用于e2e测试?
答案 0 :(得分:0)
我找到了办法。那里seems to be no reuse of configs in angular.json不太方便,但是可以。
进入angular.json
的步骤:
"build"
部分,将其命名为"build-e2e"
"serve"
部分,将其命名为"serve-e2e"
"browserTarget": "my-project:build-e2e"
"my-project-e2e"
> "architect"
> "e2e"
> "configurations"
> "production"
> "devServerTarget"
更改为"my-project:serve-e2e:production"
(元素在步骤3和4中创建。"my-project-e2e"
> "architect"
> "e2e"
> "options"
> "devServerTarget"
更改为"my-project:serve-e2e"
(在步骤3和4中创建的元素。完成!现在ng e2e
可以访问该html文件,而ng serve
和生产版本则不能。