我想使用Playwright为我的 Angular 应用程序运行端到端 (e2e) 浏览器测试。然而,截至 2021 年 11 月,我尚未找到 Playwright 的 Angular 示意图。
例如, Cypress有一个官方的 Angular Schematic 。这使得可以使用以下命令运行赛普拉斯 e2e 测试:
ng e2e
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以在不编写 Angular 原理图的情况下使用 Playwright 运行 Angular e2e 测试?或者我错过了 Playwright 的 Angular 示意图吗?
e2e-testing angular-cli angular angular-schematics playwright
编辑:我现在已将项目升级到 ng13,问题仍然存在。
我正在构建一个 Angular 12 13 应用程序(最初可能是在版本 8 或 9 中生成的)。我的构建命令是ng build --configuration=production --output-hashing=all
我希望MYAPP在应用程序启动时在浏览器控制台中看到写入内容,但没有出现。(实际上我想做其他事情,但 console.log 说明了我的问题)
以下片段来自main.ts
if (environment.production) {
enableProdMode();
console.log("MYAPP");
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一个应用程序,我想提取它的两个版本。
首先是包含整个应用程序的构建。
第二个是一个仅包含我的模块之一的应用程序。它还有一个单独的路由模块。
我使用文件替换来分离构建,以定义一种新的构建方式angular.json。
替代品是这些:
"fileReplacements": [
{
"replace": "projects/my-app/src/environments/environment.ts",
"with": "projects/my-app/src/environments/environment.prod.ts"
},
{
"replace": "projects/my-app/src/app/app.module.ts",
"with": "projects/my-app/src/app/app-auth-standalone.module.ts"
},
{
"replace": "projects/my-app/src/app/app-routing.module.ts",
"with": "projects/my-app/src/app/app-auth-standalone-routing.module.ts"
},
{
"replace": "projects/my-app/src/app/app.component.ts",
"with": "projects/my-app/src/app/app-auth-standalone.component.ts"
}
]
Run Code Online (Sandbox Code Playgroud)
现在,当我运行它时,ng run my-app:auth-standalone:production它会出现以下错误:
Error: <some-path>/message-bot.component.html:24:34 - error NG8002: Can't bind to 'control' since it isn't a known property of 'app-bot-view-tr
ansfer-to-user'.
1. If 'app-bot-view-transfer-to-user' is an Angular component and it has 'control' input, then verify that it is part of this module.
2. If …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Angular 提供的持久构建缓存功能,但看起来它对我不起作用,我正在尝试以下命令
NG_PERSISTENT_BUILD_CACHE=1 ng serve
Run Code Online (Sandbox Code Playgroud)
它总是返回以下错误
“NG_PERSISTENT_BUILD_CACHE”不被识别为内部或外部命令、可操作程序或批处理文件。
我正在使用 Angular cli 版本 12.2.15。我不确定我错过了什么。下面是我的packages.json 文件
"dependencies": {
"@agm/core": "^1.1.0",
"@angular-devkit/core": "^12.2.15",
"@angular/animations": "^12.2.15",
"@angular/common": "^12.2.15",
"@angular/compiler": "^12.2.15",
"@angular/core": "^12.2.15",
"@angular/forms": "^12.2.15",
"@angular/platform-browser": "^12.2.15",
"@angular/platform-browser-dynamic": "^12.2.15",
"@angular/platform-server": "^12.2.15",
"@angular/pwa": "^0.1100.2",
"@angular/router": "^12.2.15",
"@angular/service-worker": "^12.2.15",
"@auth0/angular-jwt": "5.0.2",
"@ng-bootstrap/ng-bootstrap": "^8.0.0",
"@nguniversal/module-map-ngfactory-loader": "^8.1.1",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "^6.0.0",
"@types/ckeditor": "^4.9.10",
"@types/hammerjs": "^2.0.36",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.10",
"@types/papaparse": "^5.3.1",
"@webcomponents/shadydom": "^1.9.0",
"acorn": "^8.0.4",
"angular-chart.js": "^1.1.1",
"angular-file-uploader": "7.0.3",
"angular-mydatepicker": "^0.10.2",
"angular-ng-autocomplete": "^2.0.1",
"angular-split": "4.0.0",
"angular2-datetimepicker": "^1.1.1",
"angular2-text-mask": "9.0.0", …Run Code Online (Sandbox Code Playgroud) 我在项目根级别的测试文件夹中的 src 文件夹之外有 karma 测试规范文件。将 Angular 从 14 更新到 15 后,karma 需要测试规范文件位于 angular.json 文件中 sourceRoot 指定的任何文件夹中。
// angular.json
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"project-name": {
"root": "",
"sourceRoot": "", // <<===
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉 karma 查看工作空间根级别以向下进行测试,而不更改 angular.json 中的 sourceRoot 属性?
我将 sourceRoot 路径更改为“”,然后 Karma 会找到位于工作区文件夹及其下方的测试,因为我正在寻找带有 **/*.spec.ts 的测试
// tsconfig.spec.json
"include": [
"**/*.spec.ts",
"**/*.d.ts",
]
Run Code Online (Sandbox Code Playgroud) 我已经创建了angular-cli项目。我想添加https://www.npmjs.com/package/js-sha1,所以我使用了命令。
npm install js-sha1 ---save
Run Code Online (Sandbox Code Playgroud)
我应该如何导入它才能使用它?我正在尝试将其导入为:
import 'js-sha1';
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时:
sha1('Message to hash');
Run Code Online (Sandbox Code Playgroud)
它说它不知道sha1是什么。
为了避免导入文件时出现相对路径,我尝试配置angular来理解路径。
到目前为止,我的代码根本不起作用:
//tsconfig.app.json
"compilerOptions":{
//lot of things . If it matter moduleResultion is set to node
"baseUrl": ".",
"paths": {
"@modules": ["app/modules/"]
...
},
}
//in a component:
import { X } from '@modules/Y/component/index'
Run Code Online (Sandbox Code Playgroud)
运行ng serve时,控制台输出以下错误: : Cannot find module '@modules/Y/component/index'.
这肯定是在使用相对路径 import { X } from ../../../modules/Y/component/index
因此,我希望我的tsconfig.app.json或tsconfig.json(或可能两者都出错)是错误的,但是,我找不到关于如何正确地为角度应用程序做任何好的教程。
当前将angular 4与基本的关联工具结合使用(打字稿2.3.3,angular-cli 1.0.6并提供webpack)
您能向我指出问题,还是请给我一个好的文档/教程,请用angular解决这个问题?到目前为止,我在SO或github问题上看到的所有答案都根本不起作用。
注意:体系结构看起来像这样
project
|
-tsconfig.json //had try things on this one too but does nothing.
-src/
|
-tsconfig.app.json
-app/
|
-modules
-othersFolder
Run Code Online (Sandbox Code Playgroud) 我无法让IE10加载一个全新的Angular CLI项目.运行"ng new"时,除了默认的Angular CLI包之外,没有其他代码.
我使用的是Angular 4.2.4,@ angular/cli 1.3.1和IE 10.0.9200.16519
我试过'ng build'和'ng build --prod'并且都返回相同的错误消息.该项目在其他所有浏览器上运行.
我已经取消注释了在项目的polyfills.ts中运行IE9,IE10,IE11所需的所有polyfill行(并按照文件中的说明安装了所有内容).
这4个错误是:
预期标识符polyfills.bundle.js,第6127行,第67个字符
var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7;
Run Code Online (Sandbox Code Playgroud)
对象不支持属性或方法'bind'styles.bundle.js,第279行字符3
update = applyToSingletonTag.bind(null, styleElement, styleIndex, false);
Run Code Online (Sandbox Code Playgroud)
预期标识符vendor.bundle.js,第2056行第71个字符
exports.rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ?
Symbol.for('rxSubscriber') : '@@rxSubscriber';
Run Code Online (Sandbox Code Playgroud)
Object不支持属性或方法'defineProperty'main.bundle.js,第132行字符1
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
Run Code Online (Sandbox Code Playgroud)
似乎' 符号 ',' 绑定 '和' defineProperty '是罪魁祸首.
我确实看到符号和对象es6 polyfill包含在pollyfills.ts项目文件中:
****************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all …Run Code Online (Sandbox Code Playgroud) 首先,我对Angular 5+项目中此类文件的潜在存在一无所知。我有一个正在运行的Angular 5项目,其中没有此manifest.json文件。我决定添加服务工作者工具,以提高应用程序的性能。服务人员没有被激活,我对此问题进行了一些研究,发现以下开放的github问题,其中一些人提到他们使用manifest.json解决了该问题。这是什么文件 为什么它不能成为Angular CLI配置的一部分?在什么条件下您需要一个?潜在的文件在哪里?
service-worker angular-cli angular angular5 angular-service-worker
我在一台计算机上遇到以下错误,但它可以在另一台计算机上使用相同的源代码
找不到本地工作区文件('angular.json').错误:找不到本地工作区文件('angular.json')
不工作的电脑
工作电脑
我尝试了这个stackoverflow链接中提到的命令,但没有运气
ng update @ angular/cli --migrate-only --from = 1.7.4这删除了.angular-cli.json并创建了angular.json.
如果这导致您的项目使用1.7.4,请在本地安装v6:
npm install --save-dev @ angular/cli @ v6.0.0-rc.4
不工作的计算机版本
PS D:\ Work\Source> ng -v您的全局Angular CLI版本(6.0.8)大于本地版本(6.0.0-rc.4).使用本地Angular CLI版本.
要禁用此警告,请使用"ng config -g cli.warnings.versionMismatch false".
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
Run Code Online (Sandbox Code Playgroud)
/△\ | '_\/ _ | | | | |/ _| ' | | | | | | | /\ …
angular ×10
angular-cli ×10
typescript ×3
webpack ×2
angular12 ×1
angular15 ×1
angular5 ×1
e2e-testing ×1
karma-runner ×1
playwright ×1