Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for tests under windows / jest update to 26.6.3 #1421

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions gridsome/lib/__tests__/project-basic.build.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const cheerio = require('cheerio')
const express = require('express')
const puppeteer = require('puppeteer')
const { trim, uniq } = require('lodash')
const os = require('os')

const context = path.join(__dirname, '__fixtures__', 'project-basic')
const content = file => fs.readFileSync(path.join(context, file), 'utf8')
Expand Down Expand Up @@ -105,7 +106,14 @@ test('render g-link components', () => {
test('render g-image components', () => {
const $home = load('dist/index.html')
const $about = load('dist/about/index.html')
const aboutJS = content('dist/assets/js/page--src--pages--about-vue.js')

let aboutJS
if (os.platform() === 'win32') {
aboutJS = content('dist/assets/js/page--src-pages-about-vue.js')
}
else {
aboutJS = content('dist/assets/js/page--src--pages--about-vue.js')
}

// #1318 - Exclude `dataUri` from bundle when not lazy loading the image.
expect(aboutJS).not.toMatch('"dataUri":"data:image/svg+xml')
Expand Down Expand Up @@ -178,7 +186,14 @@ test('generate /404.html', () => {

test('compile scripts correctly', () => {
const appJS = content('dist/assets/js/app.js')
const homeJS = content('dist/assets/js/page--src--pages--index-vue.js')

let homeJS
if (os.platform() === 'win32') {
homeJS = content('dist/assets/js/page--src-pages-index-vue.js')
}
else {
homeJS = content('dist/assets/js/page--src--pages--index-vue.js')
}

// never include the context path
expect(appJS).not.toMatch(context)
Expand Down
5 changes: 5 additions & 0 deletions gridsome/lib/app/__tests__/createRenderQueue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const App = require('../App')
const createApp = require('../index')
const { BOOTSTRAP_PAGES } = require('../../utils/constants')
const createRenderQueue = require('../build/createRenderQueue')
const { unwinpath } = require('../../utils/helpers')

test('create render queue for basic project', async () => {
const context = path.resolve(__dirname, '../../__tests__/__fixtures__/project-basic')
Expand Down Expand Up @@ -244,6 +245,10 @@ describe('dynamic pages', () => {
path.relative(app.config.outputDir, entry.htmlOutput)
)

outputs.forEach(function(item, index) {
outputs[index] = unwinpath(item)
})

expect(outputs).toEqual([
'a/b/index.html',
'a/_b_d_plus.html',
Expand Down
21 changes: 16 additions & 5 deletions gridsome/lib/app/codegen/__tests__/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const App = require('../../App')
const genRoutes = require('../routes')
const { NOT_FOUND_NAME } = require('../../../utils/constants')

function fixwinpath(routestr) {
routestr = routestr.replace(/\\\\/g, '/')
routestr = routestr.replace(/page--fixtures-page/g, 'page--fixtures--page')
return routestr
}

test('generate a simple route', async () => {
const app = await new App(__dirname).init()

Expand All @@ -10,7 +16,8 @@ test('generate a simple route', async () => {
component: './__fixtures__/PageA.vue'
})

expect(genRoutes(app)).toMatchSnapshot()
let testroutes = fixwinpath(genRoutes(app))
expect(testroutes).toMatchSnapshot()
})

test('generate a route with meta', async () => {
Expand All @@ -28,7 +35,8 @@ test('generate a route with meta', async () => {
}
})

expect(genRoutes(app)).toMatchSnapshot()
let testroutes = fixwinpath(genRoutes(app))
expect(testroutes).toMatchSnapshot()
})

test('generate a route with raw code as meta', async () => {
Expand All @@ -44,7 +52,8 @@ test('generate a route with raw code as meta', async () => {
}
})

expect(genRoutes(app)).toMatchSnapshot()
let testroutes = fixwinpath(genRoutes(app))
expect(testroutes).toMatchSnapshot()
})

test('generate component imports as variables', async () => {
Expand Down Expand Up @@ -73,7 +82,8 @@ test('generate component imports as variables', async () => {
component: './__fixtures__/PageC.vue'
})

expect(genRoutes(app)).toMatchSnapshot()
let testroutes = fixwinpath(genRoutes(app))
expect(testroutes).toMatchSnapshot()
})


Expand All @@ -91,5 +101,6 @@ test('generate redirect routes', async () => {
component: './__fixtures__/PageA.vue'
})

expect(genRoutes(app)).toMatchSnapshot()
let testroutes = fixwinpath(genRoutes(app))
expect(testroutes).toMatchSnapshot()
})
3 changes: 2 additions & 1 deletion gridsome/lib/graphql/__tests__/nodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const App = require('../../app/App')
const PluginAPI = require('../../app/PluginAPI')
const JSONTransformer = require('./__fixtures__/JSONTransformer')
const { unwinpath } = require('../../utils/helpers')

const context = path.resolve(__dirname, '../../__tests__')
const imagesDir = path.join(context, 'assets', 'static')
Expand Down Expand Up @@ -491,7 +492,7 @@ test('transformer should resolve absolute paths', async () => {
}`)

expect(errors).toBeUndefined()
expect(data.testPost.fileField).toEqual(`${context}/assets/image.png`)
expect(unwinpath(data.testPost.fileField)).toEqual(`${unwinpath(context)}/assets/image.png`)
})

test('process image types in schema', async () => {
Expand Down
19 changes: 10 additions & 9 deletions gridsome/lib/store/__tests__/PluginStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const App = require('../../app/App')
const PluginAPI = require('../../app/PluginAPI')
const JSONTransformer = require('./__fixtures__/JSONTransformer')
const { BOOTSTRAP_PAGES } = require('../../utils/constants')
const { unwinpath } = require('../../utils/helpers')

async function createPlugin (context = '/', localConfig) {
const app = await new App(context, { localConfig }).init()
Expand Down Expand Up @@ -604,8 +605,8 @@ test('resolve file paths', async () => {
})

expect(node.file).toEqual('image.png')
expect(node.file2).toEqual('/absolute/dir/to/project/image.png')
expect(node.file3).toEqual('/absolute/dir/to/image.png')
expect(unwinpath(node.file2)).toEqual('/absolute/dir/to/project/image.png')
expect(unwinpath(node.file3)).toEqual('/absolute/dir/to/image.png')
expect(node.filepath).toEqual('dir/to/image.png')
expect(node.url).toEqual('https://example.com/image.jpg')
expect(node.url2).toEqual('//example.com/image.jpg')
Expand Down Expand Up @@ -637,8 +638,8 @@ test('resolve file paths when folder as extension', async () => {
})

expect(node.file).toEqual('image.png')
expect(node.file2).toEqual('/absolute/dir/to/project.com/image.png')
expect(node.file3).toEqual('/absolute/dir/to/project.com/a/image.png')
expect(unwinpath(node.file2)).toEqual('/absolute/dir/to/project.com/image.png')
expect(unwinpath(node.file3)).toEqual('/absolute/dir/to/project.com/a/image.png')
expect(node.filepath).toEqual('dir/to/image.png')
})

Expand All @@ -656,7 +657,7 @@ test('resolve absolute file paths with no origin', async () => {
})

expect(node.file).toEqual('image.png')
expect(node.file2).toEqual('/absolute/dir/to/project/image.png')
expect(unwinpath(node.file2)).toEqual('/absolute/dir/to/project/image.png')
})

test('resolve absolute file paths with a custom path', async () => {
Expand All @@ -678,8 +679,8 @@ test('resolve absolute file paths with a custom path', async () => {
file: '/image.png'
})

expect(node1.file).toEqual('/path/to/dir/image.png')
expect(node2.file).toEqual('/path/to/dir/image.png')
expect(unwinpath(node1.file)).toEqual('/path/to/dir/image.png')
expect(unwinpath(node2.file)).toEqual('/path/to/dir/image.png')
})

test('don\'t touch absolute paths when resolveAbsolutePaths is not set', async () => {
Expand All @@ -698,7 +699,7 @@ test('don\'t touch absolute paths when resolveAbsolutePaths is not set', async (

expect(node.file).toEqual('image.png')
expect(node.file2).toEqual('/image.png')
expect(node.file3).toEqual('/absolute/dir/to/image.png')
expect(unwinpath(node.file3)).toEqual('/absolute/dir/to/image.png')
})

test('always resolve relative paths from filesystem sources', async () => {
Expand All @@ -713,7 +714,7 @@ test('always resolve relative paths from filesystem sources', async () => {
}
})

expect(node.file).toEqual('/absolute/dir/to/image.png')
expect(unwinpath(node.file)).toEqual('/absolute/dir/to/image.png')
})

test('dont resolve relative paths when no origin', async () => {
Expand Down
11 changes: 11 additions & 0 deletions gridsome/lib/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const os = require('os')

// Fix paths when testing under windows
exports.unwinpath = function (path) {
// Remove drive letter and change path seperator
if (os.platform() === 'win32') {
path = path.replace(/^\w:/, '').replaceAll('\\', '/')
}
return path
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"eslint-plugin-vue": "^4.7.1",
"eslint-plugin-vue-libs": "^3.0.0",
"execa": "^1.0.0",
"jest": "^24.1.0",
"jest": "^26.6.3",
"lerna": "^3.22.0",
"minimist": "^1.2.0",
"puppeteer": "^5.5.0",
Expand Down
Loading