extracted AMD/CJS tests and polyfills into outer function