test-utils
test-utils copied to clipboard
"server is not enabled" error
I'm trying to test the provided example in documentation.
that is:
import { get, setupTest } from '@nuxt/test-utils'
describe('ssr', () => {
setupTest({ server: true })
it('renders the index page', async () => {
const { body } = await get('/')
expect(body).toContain('<a>A Link</a>')
})
})
the test fails, with an error of server is not enabled
.
server is not enabled 5 | 6 | it('renders the index page', async () => { > 7 | const thePage = url('/page') | ^ 8 | // is something like 'http://localhost:6840/page' 9 | expect(sum(1, 2)).toBe(3); 10 | })
i have used the defeat configuration mentioned in the installation.
what I'm I doing wrong exactly?
Happens the same to me
I get the same thing using browser test :open_mouth:
import {createPage, setupTest} from "@nuxt/test-utils"
describe("browser", () => {
setupTest({broswser: true})
it("renders the something on page", async () => {
const page = await createPage('/')
const html = await page.innerHTML('body')
expect(html).toContain('Something')
})
})
So for anyone with this issue I'd suggest that you set up Playwright (npm i -D playwright @playwright/test
AND npx playwright install
). Then run npm run dev
and in another console run npm run test
(configured to use playwright commands, of course). If you want to automate this process you could use something like start-server-and-test. At least this is what I did, hope it helps!
@vencho-mdp I tried this approach and i still got the server not enabled error. :sob:
@vencho-mdp same here
Did u uninstalled nuxt/test-utils and removed nuxt test utils from jest.config?
This is how my command looks:
"test:e2e-but-not-run-dev-server": "npx playwright test test/e2e --config=test/e2e/config.js"
"test:e2e": "start-server-and-test 'npm run dev' 3000 'npm run test:e2e-but-not-run-dev-server'"
I would prefer to run my tests via nuxt test utils. Im unsure why a browser test is failing in my case.
Oh, in that case I dunno how to set it up correctly, but migrating was so smooth (the api is literally the same) El sáb, 19 feb 2022 a la(s) 15:54, Sergio Compean @.***) escribió:
I would prefer to run my tests via nuxt test utils. Im unsure why a browser test is failing in my case.
— Reply to this email directly, view it on GitHub https://github.com/nuxt/test-utils/issues/172#issuecomment-1046082836, or unsubscribe https://github.com/notifications/unsubscribe-auth/APXJVXPA6SLYDRM4CPCVNE3U37RPRANCNFSM5OQ3AUEA . You are receiving this because you were mentioned.Message ID: @.***>
i have the same issue, log says:
using v0.2.2 from main nuxt monorepo and nuxt v2.15.8
TypeError: Cannot read property 'sources' of undefined
at Object.<anonymous> (node_modules/@nuxt/webpack/node_modules/terser-webpack-plugin/dist/index.js:44:18)
at Object.<anonymous> (node_modules/@nuxt/webpack/node_modules/terser-webpack-plugin/dist/cjs.js:3:16)
at Object.<anonymous> (node_modules/@nuxt/webpack/dist/webpack.js:33:29)
at Object.<anonymous> (node_modules/@nuxt/builder/dist/builder.js:23:17)
at Object.<anonymous> (node_modules/nuxt/dist/nuxt.js:12:17)
at node_modules/@nuxt/test-utils/dist/index.js:110:57
● pdp › pdp page
server is not enabled
10 |
11 | it("pdp page", async () => {
> 12 | const { body } = await get("/products/body-essentials");
| ^