| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- /* eslint-disable
- no-path-concat,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- const Client = require('./helpers/Client')
- const sinon = require('sinon')
- const ClsiApp = require('./helpers/ClsiApp')
- const host = 'localhost'
- const Server = {
- run() {
- const express = require('express')
- const app = express()
- const staticServer = express.static(__dirname + '/../fixtures/')
- app.get('/:random_id/*', (req, res, next) => {
- this.getFile(req.url)
- req.url = `/${req.params[0]}`
- return staticServer(req, res, next)
- })
- return app.listen(31415, host)
- },
- getFile() {},
- randomId() {
- return Math.random().toString(16).slice(2)
- }
- }
- Server.run()
- describe('Url Caching', function () {
- describe('Downloading an image for the first time', function () {
- before(function (done) {
- this.project_id = Client.randomId()
- this.file = `${Server.randomId()}/lion.png`
- this.request = {
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\usepackage{graphicx}
- \\begin{document}
- \\includegraphics{lion.png}
- \\end{document}\
- `
- },
- {
- path: 'lion.png',
- url: `http://${host}:31415/${this.file}`
- }
- ]
- }
- sinon.spy(Server, 'getFile')
- return ClsiApp.ensureRunning(() => {
- return Client.compile(
- this.project_id,
- this.request,
- (error, res, body) => {
- this.error = error
- this.res = res
- this.body = body
- return done()
- }
- )
- })
- })
- afterEach(function () {
- return Server.getFile.restore()
- })
- return it('should download the image', function () {
- return Server.getFile.calledWith(`/${this.file}`).should.equal(true)
- })
- })
- describe('When an image is in the cache and the last modified date is unchanged', function () {
- before(function (done) {
- this.project_id = Client.randomId()
- this.file = `${Server.randomId()}/lion.png`
- this.request = {
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\usepackage{graphicx}
- \\begin{document}
- \\includegraphics{lion.png}
- \\end{document}\
- `
- },
- (this.image_resource = {
- path: 'lion.png',
- url: `http://${host}:31415/${this.file}`,
- modified: Date.now()
- })
- ]
- }
- return Client.compile(
- this.project_id,
- this.request,
- (error, res, body) => {
- this.error = error
- this.res = res
- this.body = body
- sinon.spy(Server, 'getFile')
- return Client.compile(
- this.project_id,
- this.request,
- (error1, res1, body1) => {
- this.error = error1
- this.res = res1
- this.body = body1
- return done()
- }
- )
- }
- )
- })
- after(function () {
- return Server.getFile.restore()
- })
- return it('should not download the image again', function () {
- return Server.getFile.called.should.equal(false)
- })
- })
- describe('When an image is in the cache and the last modified date is advanced', function () {
- before(function (done) {
- this.project_id = Client.randomId()
- this.file = `${Server.randomId()}/lion.png`
- this.request = {
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\usepackage{graphicx}
- \\begin{document}
- \\includegraphics{lion.png}
- \\end{document}\
- `
- },
- (this.image_resource = {
- path: 'lion.png',
- url: `http://${host}:31415/${this.file}`,
- modified: (this.last_modified = Date.now())
- })
- ]
- }
- return Client.compile(
- this.project_id,
- this.request,
- (error, res, body) => {
- this.error = error
- this.res = res
- this.body = body
- sinon.spy(Server, 'getFile')
- this.image_resource.modified = new Date(this.last_modified + 3000)
- return Client.compile(
- this.project_id,
- this.request,
- (error1, res1, body1) => {
- this.error = error1
- this.res = res1
- this.body = body1
- return done()
- }
- )
- }
- )
- })
- afterEach(function () {
- return Server.getFile.restore()
- })
- return it('should download the image again', function () {
- return Server.getFile.called.should.equal(true)
- })
- })
- describe('When an image is in the cache and the last modified date is further in the past', function () {
- before(function (done) {
- this.project_id = Client.randomId()
- this.file = `${Server.randomId()}/lion.png`
- this.request = {
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\usepackage{graphicx}
- \\begin{document}
- \\includegraphics{lion.png}
- \\end{document}\
- `
- },
- (this.image_resource = {
- path: 'lion.png',
- url: `http://${host}:31415/${this.file}`,
- modified: (this.last_modified = Date.now())
- })
- ]
- }
- return Client.compile(
- this.project_id,
- this.request,
- (error, res, body) => {
- this.error = error
- this.res = res
- this.body = body
- sinon.spy(Server, 'getFile')
- this.image_resource.modified = new Date(this.last_modified - 3000)
- return Client.compile(
- this.project_id,
- this.request,
- (error1, res1, body1) => {
- this.error = error1
- this.res = res1
- this.body = body1
- return done()
- }
- )
- }
- )
- })
- afterEach(function () {
- return Server.getFile.restore()
- })
- return it('should not download the image again', function () {
- return Server.getFile.called.should.equal(false)
- })
- })
- describe('When an image is in the cache and the last modified date is not specified', function () {
- before(function (done) {
- this.project_id = Client.randomId()
- this.file = `${Server.randomId()}/lion.png`
- this.request = {
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\usepackage{graphicx}
- \\begin{document}
- \\includegraphics{lion.png}
- \\end{document}\
- `
- },
- (this.image_resource = {
- path: 'lion.png',
- url: `http://${host}:31415/${this.file}`,
- modified: (this.last_modified = Date.now())
- })
- ]
- }
- return Client.compile(
- this.project_id,
- this.request,
- (error, res, body) => {
- this.error = error
- this.res = res
- this.body = body
- sinon.spy(Server, 'getFile')
- delete this.image_resource.modified
- return Client.compile(
- this.project_id,
- this.request,
- (error1, res1, body1) => {
- this.error = error1
- this.res = res1
- this.body = body1
- return done()
- }
- )
- }
- )
- })
- afterEach(function () {
- return Server.getFile.restore()
- })
- return it('should download the image again', function () {
- return Server.getFile.called.should.equal(true)
- })
- })
- return describe('After clearing the cache', function () {
- before(function (done) {
- this.project_id = Client.randomId()
- this.file = `${Server.randomId()}/lion.png`
- this.request = {
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\usepackage{graphicx}
- \\begin{document}
- \\includegraphics{lion.png}
- \\end{document}\
- `
- },
- (this.image_resource = {
- path: 'lion.png',
- url: `http://${host}:31415/${this.file}`,
- modified: (this.last_modified = Date.now())
- })
- ]
- }
- return Client.compile(this.project_id, this.request, (error) => {
- if (error != null) {
- throw error
- }
- return Client.clearCache(this.project_id, (error, res, body) => {
- if (error != null) {
- throw error
- }
- sinon.spy(Server, 'getFile')
- return Client.compile(
- this.project_id,
- this.request,
- (error1, res1, body1) => {
- this.error = error1
- this.res = res1
- this.body = body1
- return done()
- }
- )
- })
- })
- })
- afterEach(function () {
- return Server.getFile.restore()
- })
- return it('should download the image again', function () {
- return Server.getFile.called.should.equal(true)
- })
- })
- })
|