Skip to content

Commit

Permalink
Removes sinon and chai, Migration to Jest matchers (#103)
Browse files Browse the repository at this point in the history
* chore: removes sinon and chai and complete migration to Jest (#88)

* chore: updates changelog for chai and sinon removal
  • Loading branch information
ayusharma authored and pago committed Mar 18, 2019
1 parent 74694e3 commit 4aa5e43
Show file tree
Hide file tree
Showing 53 changed files with 2,946 additions and 2,107 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## master

### Chore & Maintenance
- Removes `Chai` and `Sinon` support, Migrates tests to use `Jest`'s matchers. [#103](https://github.com/trivago/melody/pull/103)

## 1.2.0-4 (beta)

### Features
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
"babel-preset-react": "^6.23.0",
"babel-register": "^6.23.0",
"bundlesize": "^0.15.2",
"chai": "^3.0.0",
"chai-subset": "^1.5.0",
"commitizen": "^2.9.6",
"common-tags": "^1.3.1",
"coveralls": "^3.0.0",
Expand All @@ -83,8 +81,6 @@
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-uglify": "^4.0.0",
"semver": "^5.5.1",
"sinon": "^1.17.7",
"sinon-chai": "^2.8.0",
"source-map": "^0.5.6",
"typescript": "^2.2.1",
"typescript-babel-jest": "^1.0.5"
Expand Down
10 changes: 3 additions & 7 deletions packages/melody-compiler/__tests__/AutoescapeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import chai from 'chai';
import chaiSubset from 'chai-subset';
import { expect } from 'chai';

import { CharStream, Parser, TokenStream, Lexer } from 'melody-parser';
import { extension } from 'melody-extension-core';

chai.use(chaiSubset);

describe('autoescape', function() {
describe('when parsing', function() {
it('should be parsed', function() {
const node = parse(
`{% autoescape 'html' %}
Everything will be automatically escaped in this block using the {{ strategy }} strategy.
{% endautoescape %}`,
{% endautoescape %}`
);
expect(node.expressions[0]).to.containSubset({
expect(node.expressions[0]).toMatchObject({
type: 'AutoescapeBlock',
escapeType: 'html',
expressions: [
Expand Down
63 changes: 31 additions & 32 deletions packages/melody-compiler/__tests__/CharStreamSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,93 +13,92 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect } from 'chai';
import { CharStream, EOF } from 'melody-parser';

describe('CharStream', function() {
describe('#la', function() {
it('should return EOF at the end of input', function() {
var stream = new CharStream('');
expect(stream.la(1)).to.equal(EOF);
expect(stream.la(1)).toEqual(EOF);
});

it('should return EOF when looking beyond the end of input', () => {
var stream = new CharStream('hello');
expect(stream.la(10)).to.equal(EOF);
expect(stream.la(10)).toEqual(EOF);
});

it('should return the char at the specified offset', () => {
var stream = new CharStream('hello');
expect(stream.la(0)).to.eql('h');
expect(stream.la(1)).to.eql('e');
expect(stream.la(2)).to.eql('l');
expect(stream.la(3)).to.eql('l');
expect(stream.la(4)).to.eql('o');
expect(stream.la(5)).to.equal(EOF);
expect(stream.la(0)).toEqual('h');
expect(stream.la(1)).toEqual('e');
expect(stream.la(2)).toEqual('l');
expect(stream.la(3)).toEqual('l');
expect(stream.la(4)).toEqual('o');
expect(stream.la(5)).toEqual(EOF);
});

it('should return the char from the current position', () => {
var stream = new CharStream('hello');
stream.next();
stream.next();
expect(stream.la(0)).to.eql('l');
expect(stream.la(1)).to.eql('l');
expect(stream.la(2)).to.eql('o');
expect(stream.la(3)).to.equal(EOF);
expect(stream.la(0)).toEqual('l');
expect(stream.la(1)).toEqual('l');
expect(stream.la(2)).toEqual('o');
expect(stream.la(3)).toEqual(EOF);
});
});

describe('#next', () => {
it('should advance to the next character', () => {
var stream = new CharStream('hello');
stream.next();
expect(stream.la(0)).to.eql('e');
expect(stream.la(0)).toEqual('e');
});

it('should return the current character', () => {
var stream = new CharStream('hello');
expect(stream.next()).to.eql('h');
expect(stream.next()).to.eql('e');
expect(stream.next()).to.eql('l');
expect(stream.next()).to.eql('l');
expect(stream.next()).to.eql('o');
expect(stream.next()).to.equal(EOF);
expect(stream.next()).toEqual('h');
expect(stream.next()).toEqual('e');
expect(stream.next()).toEqual('l');
expect(stream.next()).toEqual('l');
expect(stream.next()).toEqual('o');
expect(stream.next()).toEqual(EOF);
});

it('should update the line info', () => {
var stream = new CharStream(`hello
world`);
expect(stream.match('hello')).to.be.true;
expect(stream.match('hello')).toBeTruthy();
stream.next();
expect(stream.mark()).to.eql({ line: 2, column: 0, index: 6 });
expect(stream.mark()).toEqual({ line: 2, column: 0, index: 6 });
});
});

describe('#mark', () => {
it('should rewind to the marked position', () => {
var stream = new CharStream('hello'),
start = stream.mark();
expect(stream.next()).to.eql('h');
expect(stream.next()).to.eql('e');
expect(stream.next()).to.eql('l');
expect(stream.next()).to.eql('l');
expect(stream.next()).to.eql('o');
expect(stream.next()).toEqual('h');
expect(stream.next()).toEqual('e');
expect(stream.next()).toEqual('l');
expect(stream.next()).toEqual('l');
expect(stream.next()).toEqual('o');
stream.rewind(start);
expect(stream.next()).to.eql('h');
expect(stream.next()).toEqual('h');
});
});

describe('#match', () => {
it('should match a string', () => {
var stream = new CharStream('hello');
expect(stream.match('he')).to.be.true;
expect(stream.match('llo')).to.be.true;
expect(stream.match('he')).toBeTruthy();
expect(stream.match('llo')).toBeTruthy();
});

it('should fail if no match', () => {
var stream = new CharStream('hello');
expect(stream.match('hello world')).to.be.false;
expect(stream.match('hello')).to.be.true;
expect(stream.match('hello world')).toBeFalsy();
expect(stream.match('hello')).toBeTruthy();
});
});
});
2 changes: 1 addition & 1 deletion packages/melody-compiler/__tests__/CompilerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('Compiler', function() {
'foo',
'_template',
]);
expect(testScope === fooScope).toEqual(true);
expect(testScope === fooScope).toBeTruthy();
});
});

Expand Down
Loading

0 comments on commit 4aa5e43

Please sign in to comment.