[英]Include static html file with Angular CLI application only in e2e tests
我想要一个特定的静态(非Angular)html文件,该文件仅在Angular CLI应用程序中运行我的e2e测试时构建和提供。 在生产应用程序中,静态文件不应该可用。
我试图让这个工作在一个最小的repro,但没有看到我如何能做到这一点。 我首先创建了一个包含所有默认值的ng new
(Angular CLI 7.3.9)应用程序。 我这样做了:
"src/production-static-page.html",
添加到主projects
条目下的angular.json
文件中的"assets"
。 <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文件只是一个普通的生产文件,因此当我将我的应用程序部署到生产环境时也可以使用。
我没有看到我应该如何配置angular.json
文件中的"foo-bar-e2e"
项目,以便另一个html文件(假设e2e-only-static-page.html
)仅用于e2e测试?
我找到了一个方法。 它不是很方便,因为在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
和生产版本则没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.