小编Mou*_*ier的帖子

未定义 Jest 模块

我正在编写我的第一个包,我只是将它转换为与 TypeScript 兼容,但这在某种程度上影响了我的 GitHub 工作流程。当我在本地使用 Jest 运行我的测试时,它们工作得很好。当我的测试在 GitHub 上运行时,它成功了10.x,但没有12.x14.x,给我以下错误:

(node:2397) ExperimentalWarning: The ESM module loader is experimental.
ReferenceError: module is not defined
    at file:///home/runner/work/enhancedMathJS/enhancedMathJS/jest.config.js:1:1
    at ModuleJob.run (internal/modules/esm/module_job.js:146:37)
    at async Loader.import (internal/modules/esm/loader.js:182:24)
    at async readConfigFileAndSetRootDir (/home/runner/work/enhancedMathJS/enhancedMathJS/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:126:32)
    at async readConfig (/home/runner/work/enhancedMathJS/enhancedMathJS/node_modules/jest-config/build/index.js:217:18)
    at async readConfigs (/home/runner/work/enhancedMathJS/enhancedMathJS/node_modules/jest-config/build/index.js:406:26)
    at async runCLI (/home/runner/work/enhancedMathJS/enhancedMathJS/node_modules/@jest/core/build/cli/index.js:230:59)
    at async Object.run (/home/runner/work/enhancedMathJS/enhancedMathJS/node_modules/jest/node_modules/jest-cli/build/cli/index.js:163:37)
npm ERR! Test failed.  See above for more details.
enhancedmath@2.0.0 test /home/runner/work/enhancedMathJS/enhancedMathJS
jest
Run Code Online (Sandbox Code Playgroud)

文件jest.config.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  testMatch: …
Run Code Online (Sandbox Code Playgroud)

node.js jestjs github-actions

11
推荐指数
3
解决办法
3796
查看次数

找不到适合实体类型字符串的合适构造函数

昨天我来问她一个类似的问题,关于我自己的实体类型会出现一些错误。我修复了这些错误,但是现在它在实体类型字符串上抛出了一个错误,我绝对不知道如何解决此错误。

完全例外:

System.InvalidOperationException:'找不到适用于实体类型'string'的合适的构造函数。以下参数无法绑定到实体的属性:“值”,“值”,“ startIndex”,“长度”,“值”,“值”,“ startIndex”,“长度”,“值”,“值”,“ startIndex”,“长度”,“值”,“ startIndex”,“长度”,“ enc”,“ c”,“计数”,“值”。

启动应用程序时会抛出此错误:我编写了一个数据播种器以在数据库中获取一些数据。我已经在我的类范围内,ConfigureServices并在Configure方法中使用它。

public void ConfigureServices(IServiceCollection services) {
        services.Configure<CookiePolicyOptions>(options => {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        services.AddDbContext<ApplicationDbContext>(options =>
           options.UseSqlServer(
               Configuration.GetConnectionString("DefaultConnection")));
        services.AddScoped<IRatingRepository, RatingRepository>();
        services.AddScoped<IReservationRepository, ReservationRepository>();
        services.AddScoped<DataSeeder>();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core

9
推荐指数
2
解决办法
3078
查看次数

使用 supertest 测试 Express NodeJS 端点

我正在尝试设置一个测试环境来测试我的 typescript Express Nodejs 端点,但我似乎无法让它工作。我已经安装了:

  1. 笑话
  2. 开玩笑
  3. 开玩笑-junit
  4. 超级测试
  5. @类型/超级测试
  6. @类型/笑话

这是规范文件的样子:

import * as request from 'supertest';
import seed from '../../modules/contract/seed'; //empty seed function
import app from '../../index'; // export default app which is an express()

beforeAll(seed);

describe('contractService', () => {
  it('getContracts ', async () => {
    const res = await request(app).get('/getContracts');
    console.log(res.body);
  });
  it('makeContract makes and returns a new contract', async () => {
    const res = await request(app)
      .post('/makeContract')
      .send({
        name: 'testContract',
        startDate: '2019-10-3',
        challenges: []
      }); …
Run Code Online (Sandbox Code Playgroud)

node.js express typescript supertest jestjs

5
推荐指数
1
解决办法
3109
查看次数

构建时 GitHub 操作崩溃

我对 DevOps 的世界真的很陌生,我想把我的脚趾浸入水中。这就是为什么我一直在尝试设置一个简单的 GitHub Action,当我推送到 master 时,我的站点会自动部署到 Firebase,但在构建阶段出现问题:

Run npm run build
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/ChezMout/ChezMout/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/ChezMout/ChezMout/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-01-12T12_04_27_341Z-debug.log
##[error]Process completed with exit code 254.
Run Code Online (Sandbox Code Playgroud)

这是我的基本工作流程:

name: …
Run Code Online (Sandbox Code Playgroud)

npm devops github-actions

5
推荐指数
1
解决办法
1859
查看次数

ASP.NET Core 中的循环依赖

对于学校,我们必须使用 .NET Entity Core Framework 编写我们自己的 WebApi。我已经编写了我的 api,但是当我尝试在 swagger 中使用它时,它总是返回一个 HTTP 500 错误:内部服务器错误。我下载了 Fiddler 以开始调试,并在我的存储库中遇到了循环依赖错误,但我无法弄清楚这会发生在哪里。

接口(用于模拟测试)

public interface IVisitorRepository
{
    Visitor GetBy(string email);
    void AddVisitor(Visitor visitor);
    void SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

具体类

public class VisitorRepository : IVisitorRepository 
{
    private readonly ApplicationDbContext _context;
    private readonly DbSet<Visitor> _visitors;

    public VisitorRepository(ApplicationDbContext context, IVisitorRepository visitorRepository) 
    {
        _context = context;
        _visitors = _context.Visitors;
    }

    public void AddVisitor(Visitor visitor) 
    {
        _visitors.Add(visitor);
    }

    public Visitor GetBy(string email) 
    {
        return _visitors.SingleOrDefault(v => v.Email == email);
    }

    public void SaveChanges() 
    { …
Run Code Online (Sandbox Code Playgroud)

.net c# api asp.net-web-api entity-framework-core

3
推荐指数
1
解决办法
3217
查看次数

找不到适合实体类型 MyImage 的构造函数

我收到此异常:

System.InvalidOperationException HResult=0x80131509 消息=找不到适合实体类型“MyImage”的构造函数。以下构造函数的参数无法绑定到实体类型的属性:无法在“MyImage(string name, string country, Image image)”中绑定“image”。Source=Microsoft.EntityFrameworkCore StackTrace:在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConstructorBindingConvention.Apply(InternalModelBuilder modelBuilder) 在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionFrame.OnModelBuilt(InternalModelBuilder modelBuilder) 在 Microsoft.Core Microsoft.EntityFrameworkCore 中的 Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)。1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy 1.CreateValue() at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_2(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRuntimeResolver.VisitScopes.VisitScoped. ServiceLookup.CallSiteVisitor 2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope) …

.net c# entity-framework-core asp.net-core

3
推荐指数
2
解决办法
8101
查看次数

你应该提交 rc 和其他配置文件吗

我想知道是否应该将 rc 文件(例如.prettierrc或 ).firebaserc和其他配置文件(例如.editorconfigGitHub)提交到 GitHub?

git config github

2
推荐指数
1
解决办法
2630
查看次数

如何填充数组中的空位?

我正在寻找用[,,]的值填充数组中的空白点null。如果有 2 个,,我需要 3 个元素

我也希望它能在数组如下所示的情况下工作:[value,,][, value,][,,value]

if (Object.values(row).length !== row.length) {
  let newRow: any[];
  newRow = row.map(el => {
    if (el) {
      return el;
    } else {
      return 'null';
    }
  });
  console.log('newRow:: ', newRow);
  return newRow;
}
Run Code Online (Sandbox Code Playgroud)

javascript arrays

0
推荐指数
1
解决办法
2044
查看次数