From 8dda44f880124a5dd9ae87aebe5ce0dca09e8f75 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 16 Sep 2016 11:51:41 +0100 Subject: [PATCH] Speed up unit tests by only generating big fixtures once up front --- .../UpdateCompressorTests.coffee | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/services/track-changes/test/unit/coffee/UpdateCompressor/UpdateCompressorTests.coffee b/services/track-changes/test/unit/coffee/UpdateCompressor/UpdateCompressorTests.coffee index b4858b79b0..05fe923ab3 100644 --- a/services/track-changes/test/unit/coffee/UpdateCompressor/UpdateCompressorTests.coffee +++ b/services/track-changes/test/unit/coffee/UpdateCompressor/UpdateCompressorTests.coffee @@ -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 }]