test('honors the cache max evicting least recently used', async() => { await supertest(app).get('/components/test-component/test.html'); assert(babelCompileCache.has(uncompiledHtml)); const originalMax = babelCompileCache['max']; babelCompileCache['max'] = babelCompileCache.length; try { await supertest(app).get('/components/test-component/test.js'); assert(!babelCompileCache.has(uncompiledHtml), 'cached html evicted'); } finally { babelCompileCache['max'] = originalMax; } });
beforeEach((done: DoneFn) => { request(server.getApp()) .get("/api/user/1/address/2") .expect(200) .then(() => done()) .catch((error: any) => done.fail(error)); });
test('rewrites directory with proxy', async() => { await setUpProxy('normally-non-existing-path'); await supertest(proxyServer) .get( '/normally-non-existing-path/bower_components/test-component/test-file.txt') .expect(200, 'TEST COMPONENT\n'); });
beforeEach((done: DoneFn) => { app .use("/user/info", (err: any, req: any, res: any, next: any) => { err.$handlers.push("info error handler"); next(err); }) .use("/user", (err: any, req: any, res: any, next: any) => { err.$handlers.push("user error handler"); next(err); }) .use((err: any, req: any, res: any, next: any) => { err.$handlers.push("app error handler"); res.status(500).send(err.$handlers); }); spyOn(controller, "fn").and.callFake((req, res, next) => { next({ $handlers: [] }); }); request(app) .get("/user/info") .expect(500) .then((res: request.Response) => { response = res; done(); }) .catch((error) => done.fail(error)); });
beforeEach((done: DoneFn) => { infoRouter.use((err: any, req: any, res: any, next: any) => { infoFlag = true; next(err); }); userRouter.use((err: any, req: any, res: any, next: any) => { userFlag = true; next(err); }); app.use((err: any, req: any, res: any, next: any) => { rootFlag = true; res.status(500).send(err.$handlers); }); spyOn(controller, "fn").and.callFake((req, res, next) => { next(new Error("Custom")); }); request(app) .get("/user/info") .expect(500) .then((res: request.Response) => { response = res; done(); }) .catch((error) => done.fail(error)); });
test("isLogged:Error", async(t) => { const res = await request(app) .post("/test/api/user/isLogged") .set("authorization", "nope"); t.is(res.status, 401); t.falsy(res.body.isSuccess); });
test("login:Error", async(t) => { const res = await request(app) .post("/test/api/user/login") .send({password: "******", username: "******"}); t.is(res.status, 404); t.falsy(res.body.isSuccess); });
beforeEach((done: DoneFn) => { spyOn(server.getDependency<ControllerClass>(ControllerClass), "read").and.callThrough(); request(expressApp) .get("/controllers") .expect(200) .then(() => done()) .catch((error) => done.fail(error)); });
test('serves index.html, not 404', async() => { const app = getApp({root}); await supertest(app).get('/foo').expect(200).expect((res: any) => { if (!res.text.includes('INDEX')) { throw new Error('Expected body to contain INDEX'); } }); });
test('caches javascript compilation results', async() => { assert(!babelCompileCache.has(uncompiledJs)); const response = await supertest(app).get('/components/test-component/test.js'); assert(babelCompileCache.has(uncompiledJs)); assert.equal(response.text, babelCompileCache.get(uncompiledJs)); assert.equal(response.text.indexOf('class A {}'), -1, 'Did not compile'); });