onPageChange is only called in first test

It seems that the onPageChange callback is currently only called in the first test. To reproduce this behavior I have written a minimal setup:

plugin:

import { withPluginApi } from 'discourse/lib/plugin-api';

export default {
  name: 'pagechange-plugin',
  initialize() {
    console.log('*** PLUGIN INIT');
    withPluginApi('0.8.31', (api) => {
      console.log('*** API INIT', api);
      api.onPageChange((url) => console.log('*** PAGE CHANGED TO', url));
    });
  }
};

test:

import { acceptance } from 'helpers/qunit-helpers';

acceptance('pagechange');
test('test 1', async assert => {
  await visit('/t/280?test=1');
  await visit('/u/eviltrout?test=1');
  assert.ok(true);
});

test('test 2', async assert => {
  await visit('/t/280?test=2');
  await visit('/u/eviltrout?test=2');
  assert.ok(true);
});

The expected output is:

PLUGIN INIT
API INIT
PAGE CHANGED TO /t/280?test=1
PAGE CHANGED TO /u/eviltrout?test=1
PLUGIN INIT
API INIT
PAGE CHANGED TO /t/280?test=2
PAGE CHANGED TO /u/eviltrout?test=2

what I got:

PLUGIN INIT
API INIT
PAGE CHANGED TO /t/280?test=1
PAGE CHANGED TO /u/eviltrout?test=1
PLUGIN INIT
API INIT
5 Likes

Good catch, good catch! And thanks for the very detailed bug report :love_letter: :love_letter: :love_letter: :love_letter: Very much appreciated.

This should be fixed by:

Short story: we create some global scope variables to help with page tracking and they were not reset between tests, preventing page tracking to start on successive runs. This wasn’t impacting production site tracking, only tests.

Thanks!

8 Likes

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.