1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cypressテストレポート出力でハマった件

Last updated at Posted at 2019-10-20

Cypressとは

E2Eテストフレームワークです
https://www.cypress.io/

導入とレポート出力

cypressを導入をしてみてついでにレポート出力しようとしたところハマったためメモしておきます。

環境

Windows10
node v12.2.0
Nuxt.js 2.10.1
VSCode
PowerShell

ハマった内容

PS > npx mochawesome-merge > mochawesome.json
PS > npx marge mochawesome.json

✘ Some files could not be processed:
mochawesome.json
  Unexpected token � in JSON at position 0

やったこと

1.cypressインストール

 npm install cypress --save-dev

2.環境周りの設定

cypress.json
{
  "baseUrl": "http://localhost:3000",
  "fixturesFolder": "test/e2e/fixtures",
  "integrationFolder": "test/e2e/integration",
  "pluginsFile": "test/e2e/plugins/index.js",
  "supportFile": "test/e2e/support/index.js"
}

3.sample.jsの作成

  • sample2.jsも同じファイルで作成
test/e2e/integration/sample.js

/// <reference types="Cypress" />

describe('Sample tests', () => {
  it('Visits index page', () => {
    cy.visit('/');
    cy.contains('h2', 'Nuxt');
  });
});

4.scripts設定

package.json
  "scripts": {
    "e2e": "cypress run",
    "e2e:open": "cypress open"
  }

5.動作確認

npm run e2e

6.レポート関連インストール

npm install --save-dev mocha@5 mochawesome mochawesome-merge mochawesome-report-generator

7.cyperss設定更新

cypress.json
{
  "baseUrl": "http://localhost:3000",
  "fixturesFolder": "test/e2e/fixtures",
  "integrationFolder": "test/e2e/integration",
  "pluginsFile": "test/e2e/plugins/index.js",
  "supportFile": "test/e2e/support/index.js",
  "reporter": "mochawesome",
  "reporterOptions": {
    "overwrite": false,
    "html": false,
    "json": true
  }
}

8.e2e実行

  • mochawesome-reportフォルダにjsonが出力される
npm run e2e

9.出力された結果のマージ

npx mochawesome-merge > mochawesome.json
npx marge mochawesome.json

ここでハマる

解決方法

npx mochawesome-merge | Out-File -Encoding Default mochawesome.json
npx marge mochawesome.json

なぜハマったか

  • 「mochawesome-merge」で出力された「mochawesome.json」がUTF-16LEとなっていた(VScode上で) *バイナリで先頭FFFE
  • PowerShellでやるとNG、コマンドプロンプトだとOK
     ⇒ PowerShellのリダイレクトの仕様にハマっていた

ということでPowerShellでUTF8で出力する方法を探したところ上記の解決方法となりました。
*ちなみにEncodingがUTF8指定だとBOM付になりNGでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?