Speed up unit tests by only generating big fixtures once up front

This commit is contained in:
James Allen 2016-09-16 11:51:41 +01:00
parent dfe26262ec
commit 8dda44f880

View file

@ -5,14 +5,15 @@ expect = chai.expect
modulePath = "../../../../app/js/UpdateCompressor.js"
SandboxedModule = require('sandboxed-module')
bigstring = ("a" for [0 .. 2*1024*1024]).join("")
mediumstring = ("a" for [0 .. 1024*1024]).join("")
describe "UpdateCompressor", ->
beforeEach ->
@UpdateCompressor = SandboxedModule.require modulePath, requires:
"../lib/diff_match_patch": require("../../../../app/lib/diff_match_patch")
@user_id = "user-id-1"
@other_user_id = "user-id-2"
@bigstring = ("a" for [0 .. 2*1024*1024]).join("")
@mediumstring = ("a" for [0 .. 1024*1024]).join("")
@ts1 = Date.now()
@ts2 = Date.now() + 1000
@ -150,7 +151,7 @@ describe "UpdateCompressor", ->
meta: ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 6, i: @bigstring }
op: { p: 6, i: bigstring }
meta: ts: @ts2, user_id: @user_id
v: 43
}])
@ -159,47 +160,47 @@ describe "UpdateCompressor", ->
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 6, i: @bigstring }
op: { p: 6, i: bigstring }
meta: start_ts: @ts2, end_ts: @ts2, user_id: @user_id
v: 43
}]
it "should not append inserts that are too big (first op)", ->
expect(@UpdateCompressor.compressUpdates [{
op: { p: 3, i: @bigstring }
op: { p: 3, i: bigstring }
meta: ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 3 + @bigstring.length, i: "bar" }
op: { p: 3 + bigstring.length, i: "bar" }
meta: ts: @ts2, user_id: @user_id
v: 43
}])
.to.deep.equal [{
op: { p: 3, i: @bigstring }
op: { p: 3, i: bigstring }
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 3 + @bigstring.length, i: "bar" }
op: { p: 3 + bigstring.length, i: "bar" }
meta: start_ts: @ts2, end_ts: @ts2, user_id: @user_id
v: 43
}]
it "should not append inserts that are too big (first and second op)", ->
expect(@UpdateCompressor.compressUpdates [{
op: { p: 3, i: @mediumstring }
op: { p: 3, i: mediumstring }
meta: ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 3 + @mediumstring.length, i: @mediumstring }
op: { p: 3 + mediumstring.length, i: mediumstring }
meta: ts: @ts2, user_id: @user_id
v: 43
}])
.to.deep.equal [{
op: { p: 3, i: @mediumstring }
op: { p: 3, i: mediumstring }
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 3 + @mediumstring.length, i: @mediumstring }
op: { p: 3 + mediumstring.length, i: mediumstring }
meta: start_ts: @ts2, end_ts: @ts2, user_id: @user_id
v: 43
}]