Skip to content

Commit 9544d79

Browse files
committed
Use case-insensitive matching when comparing content-type
See #583 The "charset=utf-8" in content-type sometimes changes in tests depending on what express middleware serves the response. The charset value is case-insensitive according to IANA (see: https://www.iana.org/assignments/character-sets/character-sets.xhtml) This adds chai-string (http://chaijs.com/plugins/chai-string/) as a devDep and uses its `equalIgnoreCase` matcher in tests that check the value of the content-type header.
1 parent 4ce71a6 commit 9544d79

7 files changed

Lines changed: 26 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"broccoli-test-helper": "^1.1.0",
4444
"chai": "^4.1.0",
4545
"chai-fs": "^2.0.0",
46+
"chai-string": "^1.4.0",
4647
"co": "^4.6.0",
4748
"ember-ajax": "^3.0.0",
4849
"ember-cli": "~3.0.0",

test/custom-html-file-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
3+
const expect = require('chai').use(require('chai-string')).expect;
44
const RSVP = require('rsvp');
55
const request = RSVP.denodeify(require('request'));
66

@@ -35,7 +35,7 @@ describe('custom htmlFile', function() {
3535
})
3636
.then(function(response) {
3737
expect(response.statusCode).to.equal(200);
38-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
38+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
3939

4040
expect(response.body).to.contain("<title>custom index</title>");
4141
expect(response.body).to.contain("<h1>application template</h1>");

test/head-content-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
3+
const expect = require('chai').use(require('chai-string')).expect;
44
const RSVP = require('rsvp');
55
const request = RSVP.denodeify(require('request'));
66

@@ -37,7 +37,7 @@ describe('head content acceptance', function() {
3737
}})
3838
.then(function(response) {
3939
expect(response.statusCode).to.equal(200);
40-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
40+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
4141
expect(response.body).to.contain('<meta property="og:title" content="Head Data Title">');
4242
expect(response.body).to.not.contain('<!-- EMBER_CLI_FASTBOOT_HEAD -->');
4343
});

test/root-url-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
3+
const expect = require('chai').use(require('chai-string')).expect;
44
const RSVP = require('rsvp');
55
const request = RSVP.denodeify(require('request'));
66

@@ -35,7 +35,7 @@ describe('rootUrl acceptance', function() {
3535
})
3636
.then(function(response) {
3737
expect(response.statusCode).to.equal(200);
38-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
38+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
3939
expect(response.body).to.contain("Welcome to Ember.js");
4040
});
4141
});
@@ -49,7 +49,7 @@ describe('rootUrl acceptance', function() {
4949
})
5050
.then(function(response) {
5151
expect(response.statusCode).to.equal(200);
52-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
52+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
5353
expect(response.body).to.contain("Welcome to Ember.js");
5454
});
5555
});
@@ -63,7 +63,7 @@ describe('rootUrl acceptance', function() {
6363
})
6464
.then(function(response) {
6565
expect(response.statusCode).to.equal(200);
66-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
66+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
6767
expect(response.body).to.contain("<!-- EMBER_CLI_FASTBOOT_BODY -->");
6868
});
6969
});

test/serve-assets-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
3+
const expect = require('chai').use(require('chai-string')).expect;
44
const RSVP = require('rsvp');
55
const request = RSVP.denodeify(require('request'));
66

@@ -30,7 +30,7 @@ describe('serve assets acceptance', function() {
3030
return request('http://localhost:49741/assets/vendor.js')
3131
.then(function(response) {
3232
expect(response.statusCode).to.equal(200);
33-
expect(response.headers["content-type"]).to.eq("application/javascript; charset=utf-8");
33+
expect(response.headers["content-type"]).to.equalIgnoreCase("application/javascript; charset=utf-8");
3434
expect(response.body).to.contain("Ember =");
3535
});
3636
});
@@ -39,7 +39,7 @@ describe('serve assets acceptance', function() {
3939
return request('http://localhost:49741/assets/dummy.js')
4040
.then(function(response) {
4141
expect(response.statusCode).to.equal(200);
42-
expect(response.headers["content-type"]).to.eq("application/javascript; charset=utf-8");
42+
expect(response.headers["content-type"]).to.equalIgnoreCase("application/javascript; charset=utf-8");
4343
expect(response.body).to.contain("this.route('posts')");
4444
});
4545
});

test/simple-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
3+
const expect = require('chai').use(require('chai-string')).expect;
44
const RSVP = require('rsvp');
55
const request = RSVP.denodeify(require('request'));
66

@@ -35,7 +35,7 @@ describe('simple acceptance', function() {
3535
})
3636
.then(function(response) {
3737
expect(response.statusCode).to.equal(200);
38-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
38+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
3939
expect(response.body).to.contain("Welcome to Ember.js");
4040
});
4141
});
@@ -49,7 +49,7 @@ describe('simple acceptance', function() {
4949
})
5050
.then(function(response) {
5151
expect(response.statusCode).to.equal(200);
52-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
52+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
5353
expect(response.body).to.contain("Welcome to Ember.js");
5454
});
5555
});
@@ -63,7 +63,7 @@ describe('simple acceptance', function() {
6363
})
6464
.then(function(response) {
6565
expect(response.statusCode).to.equal(200);
66-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
66+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
6767
expect(response.body).to.contain("<!-- EMBER_CLI_FASTBOOT_BODY -->");
6868
});
6969
});
@@ -77,7 +77,7 @@ describe('simple acceptance', function() {
7777
})
7878
.then(function(response) {
7979
expect(response.statusCode).to.equal(200);
80-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
80+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
8181
expect(response.body).to.contain("Welcome to Ember.js");
8282
expect(response.body).to.contain("Posts Route!");
8383
});
@@ -92,7 +92,7 @@ describe('simple acceptance', function() {
9292
})
9393
.then(function(response) {
9494
expect(response.statusCode).to.equal(200);
95-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
95+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
9696
expect(response.body).to.contain("<!-- EMBER_CLI_FASTBOOT_BODY -->");
9797
});
9898
});
@@ -106,7 +106,7 @@ describe('simple acceptance', function() {
106106
})
107107
.then(function(response) {
108108
expect(response.statusCode).to.equal(500);
109-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
109+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
110110
expect(response.body).to.contain("BOOM");
111111
});
112112
});
@@ -121,7 +121,7 @@ describe('simple acceptance', function() {
121121
.then(function(response) {
122122
console.log(response.body);
123123
expect(response.statusCode).to.equal(200);
124-
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
124+
expect(response.headers["content-type"]).to.equalIgnoreCase("text/html; charset=utf-8");
125125
expect(response.body).to.contain("FastBoot compatible vendor file: FastBoot default default value");
126126
});
127127
});
@@ -131,7 +131,7 @@ describe('simple acceptance', function() {
131131
.then(function(response) {
132132
// Asset serving is on by default
133133
expect(response.statusCode).to.equal(200);
134-
expect(response.headers["content-type"]).to.eq("application/javascript; charset=utf-8");
134+
expect(response.headers["content-type"]).to.equalIgnoreCase("application/javascript; charset=utf-8");
135135
expect(response.body).to.contain("Ember =");
136136
});
137137
});
@@ -141,7 +141,7 @@ describe('simple acceptance', function() {
141141
.then(function(response) {
142142
// Asset serving is on by default
143143
expect(response.statusCode).to.equal(200);
144-
expect(response.headers["content-type"]).to.eq("application/javascript; charset=utf-8");
144+
expect(response.headers["content-type"]).to.equalIgnoreCase("application/javascript; charset=utf-8");
145145
expect(response.body).to.not.contain("autoBoot: false");
146146
});
147147
});

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,10 @@ chai-fs@^2.0.0:
14971497
bit-mask "^1.0.1"
14981498
readdir-enhanced "^1.4.0"
14991499

1500+
chai-string@^1.4.0:
1501+
version "1.4.0"
1502+
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.4.0.tgz#359140c051d36a4e4b1a5fc6b910152f438a8d49"
1503+
15001504
chai@^4.1.0:
15011505
version "4.1.2"
15021506
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"

0 commit comments

Comments
 (0)