Created
September 5, 2019 17:32
-
-
Save lcoenen/dae8c9d890ba7dae8eb55a5d84509845 to your computer and use it in GitHub Desktop.
As-pect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AS-pect⚡ Test suite runner [2.4.1] | |
[Log] Loading asc compiler | |
[Log] Compiler loaded in 430.424ms. | |
[Log] Using configuration /Users/lxx/xxx/server/as-pect.config.js | |
[Log] Using SummaryReporter | |
[Log] Including files: assembly/__tests__/**/*.spec.ts | |
[Log] Running tests that match: (:?) | |
[Log] Running groups that match: (:?) | |
[Log] Effective command line args: | |
[TestFile.ts] node_modules/@as-pect/assembly/assembly/index.ts --runtime full --validate --debug --binaryFile output.wasm --explicitStart --use ASC_RTRACE=1 | |
❌ assembly/__tests__/main.spec.ts Pass: 2 / 3 Todo: 0 Time: 3.757ms | |
Failed: translate | |
❌ should translate an incoming message to a SQL query - No assertion message provided. | |
[Error]: Orphaned Decrement Error An orphaned decrement has occurred at block: 2944 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { handler, Message, translate } from '../main'; | |
describe("message", () => { | |
it('should have a type', () => { | |
let message: Message<string> = new Message<string>('dummy', 'payload'); | |
expect<string>(message.action).toBe('dummy', "message.action should be 'dummy'"); | |
}) | |
it('should have a payload', () => { | |
let message: Message<string> = new Message<string>('dummy', 'payload'); | |
expect<string>(message.payload).toBe('payload', "message.payload should be 'payload'"); | |
}) | |
}); | |
describe("translate", () => { | |
it("should translate an incoming message to a SQL query", () => { | |
let incoming: Message<string> = new Message<string>('incoming', 'payload'); | |
let output: Message<string> = translate(incoming); | |
let dummySQLpayload = "SELECT * FROM dummy WHERE id = 'payload'"; | |
expect<string>(output.payload).toBe(dummySQLpayload, 'translate() answer should have the dummy SQL as a payload') | |
// expect<string>(output.action).toBe('query', 'translate() answer should have "query" as a payload') | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This represent a message flowing through the system | |
*/ | |
export class Message<T> { | |
constructor(public action: string, public payload: T) { }; | |
} | |
/* | |
* | |
* This function will attempt to translate a 'request' | |
* message into an 'answer'. | |
* | |
* If it cannot, it will answer a 'query' message. | |
* | |
*/ | |
export function translate(input: Message<string>) : Message<string> { | |
let query = "SELECT * FROM dummy WHERE id = '" + input.payload + "'"; | |
return new Message('query', query); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just replacing the constructor by