Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when i run the test examples of mocha,it throw an error #256

Closed
itlixiaolong opened this issue Dec 12, 2018 · 13 comments
Closed

when i run the test examples of mocha,it throw an error #256

itlixiaolong opened this issue Dec 12, 2018 · 13 comments

Comments

@itlixiaolong
Copy link

itlixiaolong commented Dec 12, 2018

Software versions

  • OS: window 10
  • Consumer Pact library: "@pact-foundation/pact": "^7.2.0"
  • Provider Pact library:none
  • Node Version: v8.11.2

Expected behaviour

2passing
TBC

Actual behaviour

[2018-12-12T10:55:56.596Z] ERROR: pact-node@6.20.0/25780 on SYS-20180608SQD:
Pact Binary Error: C:/Users/Administrator/Desktop/pact-js-master/pact-js-master/examples/mocha/node_modules/@pact-foundation/pact-node/standalone/win32-1.61.1/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/settings.rb:40: warning: failed to load encoding (CP936); use ASCII-8BIT instead
2018-12-12T10:55:57.711Z] WARN: pact-node@6.20.0/25780 on SYS-20180608SQD: Pact exited with code 1.
[2018-12-12T10:55:57.712Z] INFO: pact-node@6.20.0/25780 on SYS-20180608SQD: Removing Pact with
PID: 32736
����: û���ҵ����� "32736"��
1) "before all" hook

0 passing (10s)
1 failing

  1. The Dog API
    "before all" hook:
    Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\Administrator\Desktop\pact-js-master\pact-js-master\examples\mocha\test\get-dogs.spec.js)
    TBC

Steps to reproduce

"use strict";

const expect = require("chai").expect;
const path = require("path");
const { Pact } = require('@pact-foundation/pact')
const { getMeDogs, getMeDog } = require("../index");

describe("The Dog API", () => {
let url = "http://localhost";
const port = 8992;

const provider = new Pact({
port: port,
log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "pacts"),
spec: 2,
consumer: "MyConsumer",
provider: "MyProvider",
pactfileWriteMode: "merge"
});

const EXPECTED_BODY = [
{
dog: 1
},
{
dog: 2
}
];

// Setup the provider
before(() => provider.setup());

// Write Pact when all tests done
after(() => provider.finalize());

// verify with Pact, and reset expectations
afterEach(() => provider.verify());

describe("get /dogs", () => {
before(done => {
const interaction = {
state: "i have a list of dogs",
uponReceiving: "a request for all dogs",
withRequest: {
method: "GET",
path: "/dogs",
headers: {
Accept: "application/json"
}
},
willRespondWith: {
status: 200,
headers: {
"Content-Type": "application/json"
},
body: EXPECTED_BODY
}
};
provider.addInteraction(interaction).then(() => {
done();
});
});

it("returns the correct response", done => {
  const urlAndPort = {
    url: url,
    port: port
  };
  getMeDogs(urlAndPort).then(response => {
    expect(response.data).to.eql(EXPECTED_BODY);
    done();
  }, done);
});

});

describe('get /dog/1', () => {
before(done => {
const interaction = {
state: 'i have a list of dogs',
uponReceiving: 'a request for a single dog',
withRequest: {
method: 'GET',
path: '/dogs/1',
headers: {
'Accept': 'application/json'
}
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json'
},
body: EXPECTED_BODY
}
}
provider.addInteraction(interaction).then(() => {
done()
})
})

it('returns the correct response', done => {
  const urlAndPort = {
    url: url,
    port: port
  }
  getMeDog(urlAndPort)
    .then(response => {
      expect(response.data).to.eql(EXPECTED_BODY)
      done()
    }, done)
})

})
});

Relevant log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link from a gist).

@mefellows
Copy link
Member

Your issue states that your using Mac osx, but i can see that it's worrie Windows, right?

I also note a comment on encoding, so my guess is that's something to look into. Might be worth doing a search through our issues to see if there anything there

@itlixiaolong
Copy link
Author

itlixiaolong commented Dec 12, 2018

i am so sorry for my carelessness, i forgot to rewrite the os of the issue template

@itlixiaolong
Copy link
Author

itlixiaolong commented Dec 12, 2018

@mefellows i saw the issues but i can not find the solution of this, a similar issues is base on react,but there is not a clear solution to resolve this, if you can provide a help, i will thanks for your kind

@mefellows
Copy link
Member

Have you seen any of these?

My guess is there is an explicit encoding set in your environment that is overriding ours, which is causing an issue.

@itlixiaolong
Copy link
Author

Thanks for your reply,but I have checked my code,There is no obvious code to set encoding , and all files default to utf-8!

@mefellows
Copy link
Member

It's not the code I'm thinking is setting it, but the OS environment itself.

Could you please print out the values of your current shell environment?

@malongqi
Copy link

Pact Binary Error: WARN: No content type found, performing text diff on body
image

Why is this error reported when the run succeeds

@itlixiaolong
Copy link
Author

Is this what you said?

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=SYS-20180608SQD
ComSpec=C:\Windows\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\Users\Administrator
LOCALAPPDATA=C:\Users\Administrator\AppData\Local
LOGONSERVER=\SYS-20180608SQD
NPM_HOME=E:\软件\nvmNode\install
NUMBER_OF_PROCESSORS=4
NVM_HOME=C:\Users\Administrator\AppData\Roaming\nvm
NVM_SYMLINK=C:\Program Files\nodejs
OneDrive=C:\Users\Administrator\OneDrive
OS=Windows_NT
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;E:\软件\Git\cmd;E:\mysql\bin;E:\软件\nvmNode\install;%NVM_HOME%;%NVM_SYMLINK%;C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\Scripts;C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32;E:\软件\Scripts;E:\软件;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;E:\软件\Microsoft VS Code\bin;E:\软件\Microsoft VS Code\Microsoft VS Code\bin;C:\Users\Administrator\AppData\Local\atom\bin;C:\Users\Administrator\AppData\Roaming\nvm;C:\Program Files\nodejs
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=8e09
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\ADMINI1\AppData\Local\Temp
TMP=C:\Users\ADMINI
1\AppData\Local\Temp
USERDOMAIN=SYS-20180608SQD
USERDOMAIN_ROAMINGPROFILE=SYS-20180608SQD
USERNAME=Administrator
USERPROFILE=C:\Users\Administrator
VSCODE_CWD=E:\syswin-work
windir=C:\Windows
TERM_PROGRAM=vscode
TERM_PROGRAM_VERSION=1.30.0
LANG=en_US.UTF-8

@mefellows
Copy link
Member

@malongqi is that issue related to this? In any case, it's a warning and obviously the text diff is working so the tests are passing. Set the appropriate Content-Type headers and that should go away.

@mefellows
Copy link
Member

Yes, thanks @itlixiaolong. I'm not sure what's going on specifically, but I'm guessing it has to do with Chinese character encodings. All I can find is https://bugs.ruby-lang.org/issues/1048. Are there any other settings you can think of that might affect encoding?

@itlixiaolong
Copy link
Author

I can't think of any other Settings that affect the character set right now,but i will keep trying,By the way, what is the correct settings of my current shell environment that you think

@stale
Copy link

stale bot commented Feb 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@almai
Copy link

almai commented Jun 10, 2022

Sorry, mefellows already answered it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants