Skip to content

Commit

Permalink
test added for AstStages.Parser method
Browse files Browse the repository at this point in the history
  • Loading branch information
ozer authored and ozer committed Nov 3, 2018
1 parent fdb2631 commit 0f4e672
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 25 deletions.
149 changes: 149 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
"test": "node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/node": "^8.10.25",
"@types/mocha": "^2.2.42",
"@types/node": "^8.10.25",
"eslint": "^4.11.0",
"expect.js": "^0.3.1",
"sinon": "^7.1.1",
"typescript": "^2.6.1",
"vscode": "^1.1.21"
},
Expand Down
73 changes: 73 additions & 0 deletions test/astStages.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const assert = require('assert')
const expect = require('expect.js')
var sinon = require('sinon')
const AstStages = require('../lib/astStages').AstStages
const stages = new AstStages()
const fs = require('fs')


suite("AST Stages", function() {
suite("Parser", () => {
/**
* stages.parseToAst(file)
* 1- test file parameter
* 2- test parsedFile variable it should be equal to given ast
* 3- returned value equal to parsedFile AST
*/
let fn = sinon.spy(AstStages.prototype, 'parseToAst')
const reactFilePath = './test/mockData/reactCodeMock.js'
const returnedAST = require('./mockData/reactCodeASTMock').reactFileAST

suite("given parameter to the parser is testing", () => {

test("it should be defined", function() {
expect(fn).to.be.a('function');

});
test("it should throw error if parameter is not string or Buffer", () => {
expect(fn).withArgs(3).to.throwException();
})

test("it should throw error if no such a file", () => {
expect(fn).withArgs('asdas').to.throwException();
})

test("it should be a valid file path", () => {
expect(fn).withArgs(reactFilePath).to.not.throwException();
})

test("it should be a JavaScript file", () => {
expect(reactFilePath).to.contain('.js');
})

test("returned value should be an Object", () => {
expect(fn).withArgs(reactFilePath).to.not.throwException();
})
})

suite("returned AST Object is testing", () => {

test("it should be an object", () => {
expect(fn(reactFilePath)).to.be.an('object');
})

test("it should not be an empy object", () => {
expect(fn(reactFilePath)).to.not.be.empty();
})

test("it should be have property named PROGRAM", () => {
expect(fn(reactFilePath)).to.have.property('program');
})

test("it shouldn't be an empty AST", () => {
expect(fn(reactFilePath)).to.not.be.empty()
})

test("it should be a valid AST", () => {
assert.deepEqual(fn(reactFilePath), returnedAST)
})

})
})

});
24 changes: 0 additions & 24 deletions test/extension.test.js

This file was deleted.

2 changes: 2 additions & 0 deletions test/mockData/reactCodeASTMock.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions test/mockData/reactCodeMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
this.setState({value: event.target.value});
}

handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}

render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}

0 comments on commit 0f4e672

Please sign in to comment.