{"size": 891, "ext": "js", "max_stars_repo_path": "test/index.js", "max_stars_repo_name": "tyler-johnson/page-trackr", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/index.js", "max_issues_repo_name": "tyler-johnson/page-trackr", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/index.js", "max_forks_repo_name": "tyler-johnson/page-trackr", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 16.5, "max_line_length": 61, "alphanum_fraction": 0.5970819304}
import test from "tape";
import pageTrackr from "../src/index";
import page from "page";
import {Computation} from "trackr";

function resetPage() {
	page.callbacks = [];
	page.exits = [];
	page.current = '';
	page.len = 0;
	delete page.__trackr;
}

test("autoruns in route", (t) => {
	t.plan(1);

	resetPage();
	pageTrackr(page);

	page(function(ctx) {
		ctx.autorun(function(comp) {
			t.ok(comp instanceof Computation, "ran autorun in route");
		});

		ctx.forceStopComputations();
	});

	page.show("/", {}, true, false);

	t.end();
});

test("removes autorun on route exit", (t) => {
	t.plan(1);

	let count = 0;
	resetPage();
	pageTrackr(page);

	page(function(ctx) {
		if (ctx.path === "/") {
			ctx.autorun(function() {
				count++;
			});
		}
	});

	page.show("/", {}, true, false);
	page.show("/other", {}, true, false);

	t.equals(count, 1, "ran autorun only once");
	t.end();
});
